jquery与另一个js冲突

时间:2011-10-19 13:02:46

标签: jquery jquery-plugins javascript

在我的网站上,我正在使用TafelTree(一个创建可折叠树状菜单的javascript)。最近我使用jQuery Coundown创建了一个小部件。

我的问题是,只要我的jQuery倒计时小部件在页面中,树状菜单就不再有效(它不显示任何内容)< p>

jQuery倒计时函数的调用是:

$(function () {
       var theDay = new Date();
       theDay = new Date(2011, 9, 19, 20, 0, 0);
       $('#evo_defaultCountdown').countdown({until: theDay, format: 'HMS'});
});

TafelTree脚本的调用是:

function TafelTreeInit () {
var struct = [{"id" : "item_280",
"txt" : '<a class="category-link">Back to School</a>',
"url" : "/back-to-school.html", "canhavechildren" : true,
"items" : [{
"id" : "item_280_277",
"txt" : '<a href="back-to-school/notebook-acer.html">notebook Acer</a>',
"canhavechildren" : false},{
"id" : "item_280_278",
"txt" : '<a href="back-to-school/desktop-monitor-acer.html">Desktop + monitor Acer </a>',
"canhavechildren" : false},{
"id" : "item_280_266",
"txt" : '<a href="back-to-school/pc-desktop-1.html">PC Desktop</a>',
"canhavechildren" : false},{
"id" : "item_280_267",
"txt" : '<a href="back-to-school/monitor.html">monitor</a>',
"canhavechildren" : false},{
"id" : "item_280_268",
"txt" : '<a href="back-to-school/laptop-mini-laptop.html">Laptop / Mini-laptop</a>',
"canhavechildren" : false},{
]}]; 
]}]; 
function funcOpen (item, response) {
   var selected = document.getElementById(item.idObj);
   var selectedParent = selected.parentNode;
   if(response == true) {
      selected.className = selected.className+' ' + selected.className + '_open';
      selectedParent.className = selectedParent.className+' ' + selectedParent.className + '_open';
      } else {
      selected.className  = 'tafelTreecontent';
      selectedParent.className = 'tafelTreecanvas';
      }
      return true;
      }

      tree = new TafelTree('menuHolder', struct, {
         'generate' : true,
         'imgBase' : SKIN_URL+'images/plugins/tree/',
          //'defaultImg' : 'page.gif',
          //'defaultImgOpen' : 'folderopen.gif',
          //'defaultImgClose' : 'folder.gif',
          'onLoad' : function(){},
          'onOpen' : funcOpen
       });

       if(tree.openAll == true || tree.openAll == 'open'){
            document.getElementById('nav_collapse').style.display = "block";
            document.getElementById('nav_expand').style.display = "none";
        } else {
            document.getElementById('nav_collapse').style.display = "none";
            document.getElementById('nav_expand').style.display = "block";
        }
}

知道导致这场冲突的原因是什么?我该如何解决?

1 个答案:

答案 0 :(得分:5)

使用它:

http://api.jquery.com/jQuery.noConflict/

在你的情况下:

jQuery.noConflict();    
jQuery(function () {
       var theDay = new Date();
       theDay = new Date(2011, 9, 19, 20, 0, 0);
       jQuery('#evo_defaultCountdown').countdown({until: theDay, format: 'HMS'});
});