How to avoid jquery conflict in dnn

旧时模样 提交于 2020-01-13 19:07:50

问题


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.


回答1:


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));

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();
        });
    });

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




回答2:


var $j = jQuery.noConflict();
$j(document).ready(function(){
    ...code goes here...
});

Try This,



来源:https://stackoverflow.com/questions/11823908/how-to-avoid-jquery-conflict-in-dnn

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!