【问题标题】:jquery checkbox unable to clickjquery复选框无法点击
【发布时间】:2012-03-02 17:20:07
【问题描述】:

仅当我单击该行但我想以两种方式单击它时,我无法选中该复选框。 这是我正在使用的方法:

$("table tr").click(function(){
    var id=$(this).attr("id");
            //This is because i dont want first row to be able to select
    if(typeof(id)!="undefined"){
        if($("#select-"+id).attr("checked")!="checked")
            $("#select-"+id).attr("checked","checked");
        else
            $("#select-"+id).removeAttr("checked");
    }
});

您还可以在这里实时查看 sabrio.eu5.org/admin.php 用户名:管理员 密码:管理员

【问题讨论】:

    标签: javascript jquery html checkbox


    【解决方案1】:

    我最好的猜测是您的 TR 点击功能正在取消被点击的复选框的默认行为。因此,当您单击复选框时,就像被单击了两次一样。

    尝试像这样为您的复选框添加点击事件...

    $("[type='checkbox']").click(function(e) {
            e.stopPropagation();
    });
    

    您需要将选择器更改为适合您的 html 的内容

    See here for a working example

    【讨论】:

      【解决方案2】:

      这会有帮助吗

           $("table tr").click(function(){
            var checkbox = $(this).find(':checkbox');
            checkbox.attr('checked', !checkbox.attr('checked'));
           });    
      

      【讨论】:

        猜你喜欢
        • 2021-06-09
        • 1970-01-01
        • 1970-01-01
        • 2017-01-18
        • 1970-01-01
        • 2014-04-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多