异步回发后的jquery不工作 [英] jquery not working after async postback

查看:66
本文介绍了异步回发后的jquery不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的UpdatePanel做异步回发。之后异步回发的jQuery功能不working.I'm使用jQuery要连接上是一个UpdatePanel内HTML表格单元格中的一些鼠标按下了mouseenter影响。这些事件必将在$(文件)。就绪

 <脚本类型=文/ JavaScript的>                $(函数()     {
    $(。csstablelisttd)。鼠标按下(功能(E)
                        {
    //鼠标按下code
    });
 $(。csstablelisttd)。的mouseenter(函数(五)
                        {
    //鼠标输入code
    });
                        $(#contentPlaceHolderMain_btnFix)。点击(函数(五)
                        {警报(警报); //这里警报生成两次的话回发时
                           // BTN点击code
                        }
                    }            < / SCRIPT>    < ASP:的UpdatePanel ID =updatePanelTableAppointment=服务器>
                            <&的ContentTemplate GT;
         <表ID =表=服务器>
             //表数据
            < /表>                        < /&的ContentTemplate GT;<&触发器GT;
                            < ASP:AsyncPostBackTrigger控件ID =btnFix事件名称=点击/>
                        < /触发器>
                    < / ASP:的UpdatePanel>


解决方案

ASP:的UpdatePanel 替换的结果内容从服务器返回。这意味着所有的鹰钩事件previously后回发是行不通的。

使用 jQuery.on() 来代替。

例如:

 <脚本类型=文/ JavaScript的>
$(函数(){    $(#表)。在(鼠标按下了mouseenter,.csstablelisttd功能(E){
        //鼠标按下和鼠标输入code
    });    $(#contentPlaceHolderMain_btnFix)。在(点击,功能(E){
        警报(警报); //这里警报生成,然后回传出现两次
        // BTN点击code
    });
});
< / SCRIPT>

注意:如果你的鼠标按下和鼠标输入code是不同的,拆出来

执行相同的每一个事件钩子,你包括将在的UpdatePanel中存在

i am doing async postback using updatepanel. after async postback jQuery functionality not working.I'm using jQuery to wire up some mousedown mouseenter effects on html table cells that are inside an UpdatePanel. The events are bound in $(document).ready

     <script type="text/javascript">

                $(function ()



     {
    $(".csstablelisttd").mousedown(function (e)
                        {
    //mouse down code
    });
 $(".csstablelisttd").mouseenter(function (e)
                        {
    //mouse entercode
    });
                        $("#contentPlaceHolderMain_btnFix").click(function (e)
                        {alert("Alert");//here alert is generate two times an then postback occurs
                           //btn click code
                        }
                    }

            </script>

    <asp:UpdatePanel ID="updatePanelTableAppointment" runat="server">
                            <ContentTemplate>
         <table id="table" runat="server">
             //table data
            </table>

                        </ContentTemplate><Triggers>
                            <asp:AsyncPostBackTrigger ControlID="btnFix" EventName="Click" />
                        </Triggers>
                    </asp:UpdatePanel>

解决方案

asp:UpdatePanel replaces the content with the result returned from the server. This means all hooked events previously will not work after a post back.

Use jQuery.on() instead.

For example:

<script type="text/javascript">
$(function () {

    $("#table").on("mousedown mouseenter", ".csstablelisttd", function (e) {
        //mouse down AND mouse enter code
    });

    $("#contentPlaceHolderMain_btnFix").on("click", function (e) {
        alert("Alert");//here alert is generate two times an then postback occurs
        //btn click code
    });
});
</script>

Note: if your mouse down and mouse enter code are different, split them out.

Do the same for every event hook you include that will exist within the UpdatePanel.

这篇关于异步回发后的jquery不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆