两个js特效冲突,貌似是函数重名问题,我自己改不明白,求大神帮改下。
第一个js:<scriptlanguage="javascript"type="text/javascript">function$(e){returndocument....
第一个js:
<script language="javascript" type="text/javascript">
function $(e) {
return document.getElementById(e);
}
document.getElementsByClassName = function(cl) {
var retnode = [];
var myclass = new RegExp('\\b' + cl + '\\b');
var elem = this.getElementsByTagName('*');
for (var i = 0; i < elem.length; i++) {
var classes = elem[i].className;
if (myclass.test(classes)) retnode.push(elem[i]);
}
return retnode;
}
var MyMar;
var speed = 1; //速度,越大越慢
var spec = 1; //每次滚动的间距, 越大滚动越快
var ipath = '{aspcms:sitepath}/Templates/{aspcms:defaulttemplate}/image/'; //图片路径
var thumbs = document.getElementsByClassName('thumb_img');
for (var i = 0; i < thumbs.length; i++) {
thumbs[i].onmouseover = function() {
$('main_img').src = this.getAttribute('rel');
$('main_img').link = this.getAttribute('link');
};
thumbs[i].onclick = function() {
location = this.getAttribute('link')
}
}
$('main_img').onclick = function() {
location = this.getAttribute('link');
}
$('gotop').onmouseover = function() {
this.src = ipath + 'rightbutton.png';
MyMar = setInterval(gotop, speed);
}
$('gotop').onmouseout = function() {
this.src = ipath + 'rightbutton.png';
clearInterval(MyMar);
}
$('gobottom').onmouseover = function() {
this.src = ipath + 'rightbutton2.png';
MyMar = setInterval(gobottom, speed);
}
$('gobottom').onmouseout = function() {
this.src = ipath + 'rightbutton2.png';
clearInterval(MyMar);
}
function gotop() {
$('showArea').scrollTop -= spec;
}
function gobottom() {
$('showArea').scrollTop += spec;
}
</script>
第二个JS:
$(function() {
var st = 180;
$('#nav_all>li').mouseenter(function() {
$(this).find('ul').stop(false, true).slideDown(st);
}).mouseleave(function() {
$(this).find('ul').stop(false, true).slideUp(st);
});
});
JS我都已经格式化过了,现在只能调用第一个js,第二个不好使 展开
<script language="javascript" type="text/javascript">
function $(e) {
return document.getElementById(e);
}
document.getElementsByClassName = function(cl) {
var retnode = [];
var myclass = new RegExp('\\b' + cl + '\\b');
var elem = this.getElementsByTagName('*');
for (var i = 0; i < elem.length; i++) {
var classes = elem[i].className;
if (myclass.test(classes)) retnode.push(elem[i]);
}
return retnode;
}
var MyMar;
var speed = 1; //速度,越大越慢
var spec = 1; //每次滚动的间距, 越大滚动越快
var ipath = '{aspcms:sitepath}/Templates/{aspcms:defaulttemplate}/image/'; //图片路径
var thumbs = document.getElementsByClassName('thumb_img');
for (var i = 0; i < thumbs.length; i++) {
thumbs[i].onmouseover = function() {
$('main_img').src = this.getAttribute('rel');
$('main_img').link = this.getAttribute('link');
};
thumbs[i].onclick = function() {
location = this.getAttribute('link')
}
}
$('main_img').onclick = function() {
location = this.getAttribute('link');
}
$('gotop').onmouseover = function() {
this.src = ipath + 'rightbutton.png';
MyMar = setInterval(gotop, speed);
}
$('gotop').onmouseout = function() {
this.src = ipath + 'rightbutton.png';
clearInterval(MyMar);
}
$('gobottom').onmouseover = function() {
this.src = ipath + 'rightbutton2.png';
MyMar = setInterval(gobottom, speed);
}
$('gobottom').onmouseout = function() {
this.src = ipath + 'rightbutton2.png';
clearInterval(MyMar);
}
function gotop() {
$('showArea').scrollTop -= spec;
}
function gobottom() {
$('showArea').scrollTop += spec;
}
</script>
第二个JS:
$(function() {
var st = 180;
$('#nav_all>li').mouseenter(function() {
$(this).find('ul').stop(false, true).slideDown(st);
}).mouseleave(function() {
$(this).find('ul').stop(false, true).slideUp(st);
});
});
JS我都已经格式化过了,现在只能调用第一个js,第二个不好使 展开
2个回答
展开全部
第一个不用改,第二个将jquery 的关键字改下,var $j=JQuery.noConflict();
将第二个所有的$改成 $j
如:
$j(function() {
var st = 180;
$j('#nav_all>li').mouseenter(function() {
$j(this).find('ul').stop(false, true).slideDown(st);
}).mouseleave(function() {
$j(this).find('ul').stop(false, true).slideUp(st);
});
});
或者直接使用jQuery
jQuery(function() {
var st = 180;
jQuery('#nav_all>li').mouseenter(function() {
jQuery(this).find('ul').stop(false, true).slideDown(st);
}).mouseleave(function() {
jQuery(this).find('ul').stop(false, true).slideUp(st);
});
});
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询