jquery与另一个js冲突

发布于 2024-12-11 07:42:57 字数 2844 浏览 0 评论 0原文

在我的网站上,我使用 TafelTree (一种创建可折叠的 JavaScript树形菜单)。最近我使用 jQuery Coundown 制作了一个小部件。

My problem is that as long as my jQuery Countdown widget is in the page, the tree menu is no longer working (it doesn't display anything)

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";
        }
}

知道是什么导致了这种冲突吗?我该如何修复它?

On my website I'm using TafelTree (a javascript that creates a collapsible tree menu). Recently I've made a widget using jQuery Coundown.

My problem is that as long as my jQuery Countdown widget is in the page, the tree menu is no longer working (it doesn't display anything)

The call of the jQuery countdown function is:

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

The call of the TafelTree script is:

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";
        }
}

Any idea what causes this conflict? How can I fix it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦情居士 2024-12-18 07:42:57

使用:

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

use this:

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

in your case:

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'});
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文