如何避免dnn中的jquery冲突 [英] How to avoid jquery conflict in dnn

查看:102
本文介绍了如何避免dnn中的jquery冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发dnn模块。随着同一页面上模块数量的增加,jQuery多次调用。

I am working on dnn modules development. Jquery is calling many times as the number of modules increases on the same page.

    (function ($) {  
        $('#grid').hoverfold();
    })(jQuery); 

这就是我用来避免冲突的方法。如果我将下一个效果使用相同的效果,它将不起作用。

This is what I used to avoid conflict. If I use the same for the next effect it is not working.

推荐答案

例如,如果您查看 /DesktopModules/Admin/HostSettings/HostSettings.ascx ,您会注意到dnn核心开发人员正在使用以下代码:

For example, If you look at /DesktopModules/Admin/HostSettings/HostSettings.ascx you will notice that dnn core developers are using following code:

(function ($, Sys) {
 $(document).ready(function () { 
    //Your code goes here.
 });
}(jQuery, window.Sys));

除此之外,如果您注意到 $ (document).ready 函数,由于更新窗格,他们重复相同的代码来处理ajax回发。这样可以确保即使启用了Ajax模块,代码也可以正常工作。

Apart from this, if you notice the $(document).ready function, they are repeating the same code to handle ajax post backs due to update pane. That will ensure your code will work ok even if module is having ajax enabled.

 $(document).ready(function () {
        setUpDnnHostSettings();
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function () {
            setUpDnnHostSettings();
        });
    });

您还可以在admin文件夹的核心中查看其他ascx控件。我希望这会有所帮助。

You can also look at other ascx controls in core in admin folder. I hope this will help.

这篇关于如何避免dnn中的jquery冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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