加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

在asp.net中启动Updatepanel后,Javascript无法正常工作

发布时间:2020-12-16 03:59:39 所属栏目:asp.Net 来源:网络整理
导读:这是我的网站 – www.superim.ir 它的模板库是bootstrap,在导航菜单中,我在代码下面使用了一些效果! $('.productbar .dropdown').on('show.bs.dropdown',function (e) { $(this).find('.dropdown-menu').first().stop(true,true).fadeIn(300); $(this).find
这是我的网站 – > www.superim.ir
它的模板库是bootstrap,在导航菜单中,我在代码下面使用了一些效果!

$('.productbar .dropdown').on('show.bs.dropdown',function (e) {
        $(this).find('.dropdown-menu').first().stop(true,true).fadeIn(300);
        $(this).find('.dropdown-menu').first().stop(true,true).animate({ top: "45px" },300);
    });

    $('.productbar .dropdown').on('hide.bs.dropdown',true).fadeOut(300);
        $(this).find('.dropdown-menu').first().stop(true,true).animate({ top: "55px" },300);
        $(this).find('.sub-menu').hide();
        $(this).find('.left-caret').addClass("right-caret").removeClass("left-caret");
    });

点击后添加到购物车按钮,更新面板将启动,此后菜单效果不起作用!

解决办法是什么?

解决方法

这是由于使用UpdatePanel的部分回发而发生的.您为控件订阅的事件将部分呈现,因此事件将丢失.要克服这种情况,您需要重新绑定控件事件.

这是混合传统ASP.Net Ajax和jQuery事件引起的常见问题.当您执行部分回发时,将重新创建DOM并丢失jQuery事件.

例:

<script type="text/javscript">
    // bind the events (jQuery way)
        $(document).ready(function() {
            bindEvents();   
        });

        // attach the event binding function to every partial update
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function(evt,args) {
            bindEvents();
        });
<script/>

Read More about PageRequest Manager on MSDN

这里bindEvents()方法包含在部分页面回发后需要重新加载的所有脚本.

希望这对你有所帮助!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读