[英]How I can disable page redirect when click on checkbox?
I have this code: 我有以下代码:
<div onClick="$(location).attr('href','updateUser.php?id=<?php echo $admin->id; ?>')" class="dbItem">
<div class="dbItemCheckbox">
<input name="se8" type="checkbox" value="<?php echo $admin->id; ?>" />
</div>
<div class="dbItemMessageIconAdmin"><img src="images/admin.png" alt="" width="20" height="23" border="0" /></div>
<div class="dpItemName"><?php echo $admin->username; ?></div>
<div class="dpItemTitle"><?php echo $te; ?></div>
<div style="left: 110px" class="dpItemDate"><?php echo $admin->registerDate; ?></div>
<div class="dpItemDelete"><a href="editUsers.php?del=<?php echo $admin->id; ?>"><img src="images/delete.png" alt="" width="11" height="10" border="0" /></a></div>
</div>
When user click on the DIV, the browser go to the update page. 当用户单击DIV时,浏览器将转到更新页面。
The problem that I am facing is when the user clicks the checkbox to check for multi delete this will also go to the update page. 我面临的问题是,当用户单击复选框以检查多删除时,这也将转到更新页面。
How I can disable this when the user click only on the checkbox. 当用户仅单击复选框时,如何禁用此功能。
Prevent the bubbling of the event on the checkbox. 防止在复选框中冒泡事件。 Try something like this:
尝试这样的事情:
$(".dbItem INPUT[type='checkbox']").click(function(evt) {
evt.stopPropagation();
});
easiest way I can see to do this would be to relocate the onclick to another div that is exclusively wrapped around everything but the checkbox. 我可以看到的最简单的方法是将onclick移到另一个div,该div专门围绕复选框以外的所有内容。 like this:
像这样:
<div class="dbItem">
<div class="dbItemCheckbox">
<input name="se8" type="checkbox" value="<?php echo $admin->id; ?>" />
</div>
<div onClick="$(location).attr('href','updateUser.php?id=<?php echo $admin->id; ?>')" >
<div class="dbItemMessageIconAdmin"><img src="images/admin.png" alt="" width="20" height="23" border="0" /></div>
<div class="dpItemName"><?php echo $admin->username; ?></div>
<div class="dpItemTitle"><?php echo $te; ?></div>
<div style="left: 110px" class="dpItemDate"><?php echo $admin->registerDate; ?></div>
<div class="dpItemDelete"><a href="editUsers.php?del=<?php echo $admin->id; ?>"><img src="images/delete.png" alt="" width="11" height="10" border="0" /></a></div>
</div>
</div>
Either in the checkbox's onclick attribute, a script section (or external javascript file) you want to include an onclick handler for the checkbox. 在复选框的onclick属性中,您都希望在脚本部分(或外部javascript文件)中添加复选框的onclick处理程序。
$('input[name="se8"]').click(function(e){
e.stopPropagation();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.