您所在的位置:首页>>编程技术

jQuery.noConflict 解决冲突问题

点击数:1500 更新时间:2014-04-06 15:20:00 来源: 厦门网站建设-返回

jQuery.noConflict(); 可以解决jQuery库与其他库冲突问题。
var j = jQuery.noConflict();
j("div p").hide(); // 基于 jQuery 的代码
$("content").style.display = "none"; // 基于其他库的 $() 代码
其中,我们可以这么说, jQuery.noConflict(); 取消了  jQuery 效果,并引出了变量
j 我们可以使用 var j 去,复原指定需要使用  jQuery  标签。

就如下面。 var j = jQuery.noConflict(); 产生j变量,替换掉所有 $.extend --$ 变量符号。

<script type="text/javascript">
var j = jQuery.noConflict();
<span style="color:#ff0000;">$</span>(pageInit);
function pageInit()
{
  <span style="color:#ff0000;">$</span>.extend(xheditor.settings,{shortcuts:{'ctrl+enter':submitForm}});
  <span style="color:#ff0000;">$</span>('#adechocontent').xheditor({height:500,width:680,tools:'Cut,Copy,Paste,Pastetext,FontSize,Bold,Italic,Underline,FontColor,Strikethrough,FontColor,|,Outdent,List,Align,Img,Source,Flash,Table,SelectAll,Link,Unlink,|,Preview,Print,Table,Media,Fullscreen,Hr,Emot,Fullscreen,About',upLinkUrl:"../../xheditor/demos/upload.php?immediate=1",upLinkExt:"zip,rar,txt",upImgUrl:"../../xheditor/demos/upload.php?immediate=1",upImgExt:"jpg,jpeg,gif,png",upFlashUrl:"../../xheditor/demos/upload.php?immediate=1",upFlashExt:"swf",upMediaUrl:"../../xheditor/demos/upload.php?immediate=1",upMediaExt:"wmv,avi,wma,mp3,mid"});
   
}
function insertUpload(arrMsg)
{
    var i,msg;
    for(i=0;i<arrMsg.length;i++)
    {
        msg=arrMsg[i];
        $("#uploadList").append('<option value="'+msg.id+'">'+msg.localname+'</option>');
    }
}
function submitForm(){<span style="color:#ff0000;">$</span>('#frmDemo').submit();}
</script>

// =========================================================

<script type="text/javascript">
 var j = jQuery.noConflict();
 <span style="color:#ff0000;">j</span>(pageInit);
 function pageInit()
 {
   <span style="color:#ff0000;">j</span>.extend(xheditor.settings,{shortcuts:{'ctrl+enter':submitForm}});
   <span style="color:#ff0000;">j</span>('#adechocontent').xheditor({height:500,width:680,tools:'Cut,Copy,Paste,Pastetext,FontSize,Bold,Italic,Underline,FontColor,Strikethrough,FontColor,|,Outdent,List,Align,Img,Source,Flash,Table,SelectAll,Link,Unlink,|,Preview,Print,Table,Media,Fullscreen,Hr,Emot,Fullscreen,About',upLinkUrl:"../../xheditor/demos/upload.php?immediate=1",upLinkExt:"zip,rar,txt",upImgUrl:"../../xheditor/demos/upload.php?immediate=1",upImgExt:"jpg,jpeg,gif,png",upFlashUrl:"../../xheditor/demos/upload.php?immediate=1",upFlashExt:"swf",upMediaUrl:"../../xheditor/demos/upload.php?immediate=1",upMediaExt:"wmv,avi,wma,mp3,mid"});
    
 }
 function insertUpload(arrMsg)
 {
     var i,msg;
     for(i=0;i<arrMsg.length;i++)
     {
         msg=arrMsg[i];
         $("#uploadList").append('<option value="'+msg.id+'">'+msg.localname+'</option>');
     }
 }
 function submitForm(){<span style="color:#ff0000;">j</span>('#frmDemo').submit();}
 </script>



【责任编辑:CSW8923
展开