Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用jquery隐藏未选中输入的表行_Javascript_Jquery_Checkbox_Input_Html Table - Fatal编程技术网

Javascript 如何使用jquery隐藏未选中输入的表行

Javascript 如何使用jquery隐藏未选中输入的表行,javascript,jquery,checkbox,input,html-table,Javascript,Jquery,Checkbox,Input,Html Table,我正在尝试做一个过滤器,当按下按钮时,它将只显示表中已选中的行 <table class="table"> <tr> <th>Name</th> <th>InUse</th> <th></th> </tr> <tr> <td>foo 1</td> &l

我正在尝试做一个过滤器,当按下按钮时,它将只显示表中已选中的行

<table class="table">
    <tr>
        <th>Name</th>
        <th>InUse</th>
        <th></th>
    </tr>
    <tr>
        <td>foo 1</td>
        <td>
            <input checked="checked" class="check-box" disabled="disabled" type="checkbox" />
        </td>
        <td>
            <a href="/AdditivesNames/Edit/5">Edit</a> |
            <a href="/AdditivesNames/Details/5">Details</a> |
            <a href="/AdditivesNames/Delete/5">Delete</a>
        </td>
    </tr>
    <tr>
        <td>foo 2</td>
        <td>
            <input checked="checked" class="check-box" disabled="disabled" type="checkbox" />
        </td>
        <td>
            <a href="/AdditivesNames/Edit/3">Edit</a> |
            <a href="/AdditivesNames/Details/3">Details</a> |
            <a href="/AdditivesNames/Delete/3">Delete</a>
        </td>
    <tr/>
    <!-- not checked -->
    <tr>
        <td>foo 3</td>
        <td>
            <input class="check-box" disabled="disabled" type="checkbox" />
        </td>
        <td>
            <a href="/AdditivesNames/Edit/5">Edit</a> |
            <a href="/AdditivesNames/Details/5">Details</a> |
            <a href="/AdditivesNames/Delete/5">Delete</a>
        </td>
    </tr>
</table>

名称
使用
富1
|
|
富2
|
|
富3
|
|
您可以使用选择器或方法检查父元素中是否存在元素

$(“按钮”)。单击(函数(){
$(“表tr”).has(“.check box:not(:checked)”).hide();
});
表格,tr,td{
边框:1px纯黑;
}

名称
使用
富1
富2
富3
富4

仅选中
请使用以下jquery代码。单击“提交”按钮,将隐藏所有未选中复选框的行

$(document).ready(function(){
    $("input[type=submit]").click(function () {
        $("input:not(:checked)").each(function () {
            $(this).closest('tr').hide();           
        });
    });
});

请使用jquery并将此代码放入标记中

  $(document).ready(function () {
    $("#btnClick").on("click", function () {
        $(".table tr").each(function () {
            if (!$(this).find("td input:checkbox").is(":checked")) {
                $(this).hide();
            }
        })
    })
});

这应该适用于您的案例。

这是一种更简单的方法。将此
传递给HTML中的
onclick()
事件处理程序,并使用jQuery:

<input type="checkbox" onClick="disablerow(this);">

function disablerow(el) {
    if (el.checked == true) {
        $(el).closest('tr').find(":input:text(:first)").attr('disabled', false);
    }
    else {
        $(el).closest('tr').find(":input:text(:first)").attr('disabled', true);
    }     
}

功能禁用行(el){
如果(el.checked==真){
$(el).closest('tr').find(“:input:text(:first)”).attr('disabled',false);
}
否则{
$(el).closest('tr').find(“:input:text(:first)”).attr('disabled',true);
}     
}

@Yogi\u Bear不工作是什么意思?你检查过JSFIDLE吗?这两个代码在demono中都能工作,我在自己的web应用程序上尝试过,但都不起作用。我想这是因为asp。net@Yogi_Bear使用
$(文档)。在(“单击”,“按钮”,function(){})
instead上,我想禁用包含复选框的表行,如果未选中,如何禁用it@Anburaj_N你能用html给我看吗?如果还没修好,我会帮你的