简体   繁体   English

“单击行时重定向到页面,单击复选框时启用按钮”中的错误。

[英]Error in 'Redirect to a page when clicked on a row, enable a button when checkbox clicked.'

I have an HTML table . 我有一个HTML表 It shows data from database. 它显示数据库中的数据。 7 columns. 7列。 (One of them is a checkbox) (其中一个是复选框)

There's a button outside of the table. 桌子外面有个按钮。 Delete users button is initially disabled. 删除用户按钮最初被禁用。

<a id="deleteuser" class="btn btn-danger btn-sm disabled" ><i class="fa fa-trash-o"></i> Delete users</a>

It gets enabled when a checkbox is clicked. 单击复选框会启用它。 My Checkbox : 我的复选框

<input type="checkbox" name="chk" id="chk>

jQuery for enabling/disabling button: jQuery用于启用/禁用按钮:

$(function(){
var button=$('#deleteuser');
button.attr('disabled','disabled');
$('#chk').change(function(e){
if(this.checked){
button.removeAttr('disabled');
} else {
button.attr('disabled','disabled');
}
});
});

It's fine till now. 到目前为止还好。 Now I've to add one more functionality to this table. 现在,我必须在此表中添加其他功能。 When any row is clicked, contents of that row has to redirect to another page so that I can modify that data. 单击任何行时,该行的内容必须重定向到另一页,以便我可以修改该数据。

To make table click-able, I used this CSS : 为了使表格可点击,我使用了以下CSS

<style>
    table, table tr, table tr td { cursor: pointer;}
</style>

And to edit a particular row, I redirect that row's content (based on User id) to another page. 为了编辑特定的行,我将该行的内容(基于用户ID)重定向到另一个页面。 Script I used: 我使用的脚本:

$(document).ready(function(){
$('table.table tr').click(function () {

        window.location='edituserdata.php'
    });

});

----------THE PROBLEM-------------- - - - - - 问题 - - - - - - -

Now when I click on a row, I get redirected to edituserdata.php ( even when I click a checkbox ). 现在,当我单击一行时,我将重定向到edituserdata.php( 即使单击复选框也是如此 )。 I want to enable delete user button when I click a checkbox and to redirect to another page when I click on any other columns in that row . 我想在单击复选框时启用“删除用户”按钮,在单击该行中的任何其他列时重定向到另一页 I went wrong somewhere...can't figure it out. 我在某个地方出错了...无法解决。 Anyone to help??? 有人帮忙吗??? Both works, but doesn't work together. 两者都可以,但是不能一起使用。

JSFiddle: JSFiddle:

http://jsfiddle.net/iamsajeev/8eMDG/ http://jsfiddle.net/iamsajeev/8eMDG/

you can check the target click event of the row by checking the target nodeName and prevent further task if it is an anchor. 您可以通过检查目标nodeName来检查行的目标click事件,如果它是锚点,则可以阻止进一步的任务。 you can also check the checkbox. 您还可以选中该复选框。

$('table.table tr').click(function (ev) {
    if(ev.target.nodeName.toLowerCase() == "a") return;
    if(ev.target.nodeName.toLowerCase() == "input")return;
});

I believe you can also use is to check the element. 相信您也可以使用的is检查元素。

$('table.table tr').click(function (ev) {
    if($(ev.target).is("a")) return;
    if($(ev.target).is("input[type=checkbox]"))return;
});

Fiddle 小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 单击复选框不会删除新任务。 - New tasks won't delete when checkbox clicked. 单击复选框时无法发出事件。 (socket.io) - Unable to emit event when a checkbox is clicked. (socket.io) Spinner 仅在单击按钮时处理页面中的一个按钮。 其他人不显示微调器 - Spinner Working on only One button in a page when the button is clicked. Others dont show spinner 单击增量按钮时,进度条的宽度将发生变化。 使用Javascript - Progress Bar width to change when increment button clicked. Javascript 单击“更多”按钮位置时出错。 - “Read More” button position goes wrong when it is clicked.? 编写一个 javascript 函数,在单击按钮时将表单的详细信息打印到另一个 html 页面。 - Writing a javascript function that just prints details of a form to another html page when a button is clicked. 单击删除按钮时,删除相应的项目。 BackboneJs - Remove corresponding item when delete button is clicked. BackboneJs 单击发送按钮时如何将“给定文本”附加到文本区域。? - How to append “given text” with a textarea when send button is clicked.? 单击按钮时在两个功能之间切换。 - Toggle between two functions when button clicked. 如何在单击电子邮件正文中的按钮时更新Google工作表。 - how to update the google sheet when button in email body is clicked.?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM