【问题标题】:jQuery not working after Updatepanel Refresh更新面板刷新后 jQuery 不工作
【发布时间】:2017-03-17 05:12:52
【问题描述】:

谁能澄清我如何在更新面板刷新后调用该函数。我已经通过这个link 阅读了参考资料,但我不知道在call function here 的地方提供什么。

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type = "text/javascript">
        var jq5 = $.noConflict(true);
        jq5(document).ready(function () {
            var CheckAll = jq5("#chkAll").click(function () {
                if (this.checked) {
                    jq5('.chk').attr('checked', this.checked);
                }
                else {
                    jq5('.chk').attr('checked', this.checked = false);
                }
            });
            jq5(".chk").click(function () {
                if (jq5(".chk").length == jq5(".chk:checked").length) {
                    jq5("#chkAll").attr("checked", "checked");
                } else {
                    jq5("#chkAll").removeAttr("checked");
                }
            });
        });

    var prm = Sys.WebForms.PageRequestManager.getInstance();
    if (prm != null) {
        prm.add_endRequest(function (sender, e) {
            if (sender._postBackSettings.panelsToUpdate != null) {
                // call function here...
            }
        });
    };
</script>

【问题讨论】:

    标签: jquery asp.net updatepanel


    【解决方案1】:

    您可能需要在每次更新面板请求之后添加事件监听器。

    var jq5 = $.noConflict(true);
    jq5(document).ready(function () {
            AddClickEvent();
    });
    
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    if (prm != null) {
        prm.add_endRequest(function (sender, e) {
    
            AddClickEvent();
    
            if (sender._postBackSettings.panelsToUpdate != null) {
                // call function here...
            }
        });
    };
    
    function AddClickEvent(){
                var CheckAll = jq5("#chkAll").click(function () {
                    if (this.checked) {
                        jq5('.chk').attr('checked', this.checked);
                    }
                    else {
                        jq5('.chk').attr('checked', this.checked = false);
                    }
                });
                jq5(".chk").click(function () {
                    if (jq5(".chk").length == jq5(".chk:checked").length) {
                        jq5("#chkAll").attr("checked", "checked");
                    } else {
                        jq5("#chkAll").removeAttr("checked");
                    }
                });
    }
    

    【讨论】:

    • 已经解决了,不过感谢您的替代解决方案
    【解决方案2】:

    解决了。刚改了 (document).ready(function () 到 function pageLoad(sender, args)

    【讨论】:

      猜你喜欢
      • 2017-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多