当我的页面加载时,我隐藏一个包含表单的 div
$('#popupPerson').hide();
然后在正文中,我构建一个表和此弹出窗口,以帮助使用最初隐藏的表单插入/更新/删除行数据
<div id="popupPerson" class="popupPerson">
<form id="form_popup_person" action="person_update" method="post">
<fieldset>
<legend>Person</legend>
<label for="id">id</label> <input name="id" type="number" />
<label for="revision">revision</label> <input name="revision" type="number" /><p>
<label for="lastName">lastName</label> <input name="lastName" type="text" />
<label for="firstName">firstName</label> <input name="firstName" type="text" /><p>
<label for="street">street</label> <input name="street" type="text" />
<label for="city">city</label> <input name="city" type="text" /><p>
<label for="county">county</label> <input name="county" type="text" />
<label for="state">state</label> <input name="state" type="text" />
<label for="postalCode">postalCode</label> <input name="postalCode" type="text" /><p>
<label for="birthDate">birthDate</label> <input name="birthDate" type="text" />
<label for="email">email</label> <input name="email" type="text" />
<label for="status">status</label> <input name="status" type="text" /><p>
<input name="submit" type="submit" value="Submit" />
<input name="cancel" type="submit" class="cancel" value="Cancel" />
<button type="button" class="cancel" onClick="this.parent.close();">Cancel button</button>
<button type="button" class="cancel" onClick="$(this).parent().parent().hide();">parent parent hide button</button>
<button type="button" class="cancel" onClick="$(this).parent().hide();">parent hide button</button> <!-- makes ALL BUTTONS DISAPPEAR -->
<button type="button" class="cancel" onClick="$(this).hide();">hide button</button> <!-- makes the BUTTON ITSELF DISAPPEAR -->
</fieldset>
</form>
</div>
还有一些js,这样如果单击表中的一行,就会触发并使div可见
$('#popupPerson').show();
我想在表单中添加一个“取消”按钮,用于简单地关闭/隐藏 div - 无需提交,无需重置。
最佳答案
你可以简单地这样写
<button type="button" class="cancel" onClick="$('#popupPerson').hide();">Cancel</button>
关于javascript - 隐藏/关闭由 .show() 打开的 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51862706/