简体   繁体   English

单击复选框时如何禁用页面重定向?

[英]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.

相关问题 单击浏览器的后退按钮时如何在主页上重定向 - how can i redirect on the home page when i click on browser's back button 如何在复选框单击时禁用textarea? - How do I disable textarea on checkbox click? 当我单击注销按钮时,会打开确认警报。 当我取消时,它将重定向登录页面,但我想重定向当前页面。 我该怎么做? - When i click in logout button open a confirm alert. When i cancel it will redirect login page but i want to redirect current page. How i can do it? 单击取消时如何将复选框设置为未选中 - How can I set a checkbox to unchecked when I click cancel 如何通过单击HTML中的超链接重定向到另一页? - How can i redirect to another page by click on hyperlink in Html? 单击按钮时如何重定向到我的网站? - How can I redirect to my website when I click a button? 如果选中任何复选框并在未选中任何复选框时禁用它,如何启用提交按钮? - How can I enable a submit button if any checkbox is checked and disable it when none checkbox is checked? 单击按钮提交时如何禁用操作表单? - How can I disable action form when click button submit? 如何在ExtJS中禁用网格上的复选框? - How can I disable checkbox on the grid in ExtJS? 当页面上没有复选框时禁用复选框 - Disable checkbox when no checkboxes on page
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM