选择jquery中无法正常工作的所有函数

选择jquery中无法正常工作的所有函数,jquery,asp.net-mvc-4,Jquery,Asp.net Mvc 4,我有一个搜索栏和它下面的一个表,它有一个全选选项。全选功能工作正常,但当我在搜索栏中搜索某个内容,然后单击全选按钮时,什么也没有发生。我不明白为什么会这样 这是我的全选功能代码 function selectUnselectchkAllProcessedOrders() { debugger $("#chkAllProcessedOrders").click(function () { var checked_status = this.checked;

我有一个搜索栏和它下面的一个表,它有一个全选选项。全选功能工作正常,但当我在搜索栏中搜索某个内容,然后单击全选按钮时,什么也没有发生。我不明白为什么会这样

这是我的全选功能代码

    function selectUnselectchkAllProcessedOrders() {
    debugger
    $("#chkAllProcessedOrders").click(function () {
        var checked_status = this.checked;
        $("input[name='fulfillmentOrderId']").each(function () {
            this.checked = checked_status;

            if (checked_status)
                $(this).parent().parent().addClass('greanBackGround');
            else
                $(this).parent().parent().removeClass('greanBackGround');
        });

    });
}
单击“搜索”按钮后单击“全选”复选框时,我可以使用调试器看到,当调用selectUnselectchkAllProcessedOrders()函数时,this.checked未定义

这里是cshtml

  <div>
        <table>
            <tr>
                <td>
                    <label>Order Number</label></td>
                <td>
                    <input type="text" id="TextBoxFullFillmentOrderNumber" 
/></td>
                <td>
                    <input type="submit" name="ButtonSearch" value="Search" 
/>
                    <input type="hidden" name="posearchorderno" 
id="posearchorderno" />
                    <input type="hidden" name="search" value="some" />
                </td>

            </tr>
            <tr></tr>
        </table>
    </div>
    }

订单号
}

尝试以下操作:您正在尝试为动态创建的复选框绑定单击事件,因此请在上使用
,如下所示

$(document).on("click","#chkAllProcessedOrders", function () {
    var checked_status = this.checked;
    $("input[name='fulfillmentOrderId']").each(function () {
        this.checked = checked_status;

        if (checked_status)
            $(this).parent().parent().addClass('greanBackGround');
        else
            $(this).parent().parent().removeClass('greanBackGround');
    });

});

请单击
并创建一个带有普通呈现html的。我假设你的asp创建了你想要的html,所以它不是aspquestion@mplungjan现在好了吗?没有。单击代码段编辑器,创建一个只包含脚本和HTML的运行代码段。如果没有serverSee副本,我们无法测试cshtml。如果您在@mplungjan中发布了HTML而不是CSHTML,我可能会在20分钟前关闭它。对不起,我不知道必须发布原始HTML而不是CSHTML。我希望现在天气好。谢谢。这个很好用。你能解释一下出了什么问题吗?很抱歉,我没有理解你,我不擅长jquery@S.J.Lee,在搜索之后,您将创建新的html元素以显示结果以及“全选”按钮。因此,先前附加的
“#chkAllProcessedOrders”
的单击处理程序将无法工作,因为它已被销毁。JQuery提供了一种为动态创建的元素绑定事件处理程序的方法。请查看更多详细信息,非常感谢!那有帮助!