jquery与一段js冲突,求解决
引用了jquery库,结果与现有的一段js冲突,jquery失效,求解决。<scripttype="text/javascript"src="{URLROOT}/stat...
引用了jquery库,结果与现有的一段js冲突,jquery失效,求解决。
<script type="text/javascript" src="{URLROOT}/static/javascript/jquery.js"></script>
<script type="text/javascript">
(function() {
var pthis = this;
this.$ = function(a) {
if (document.getElementById) {
return eval('document.getElementById("' + a + '")')
} else {
if (document.layers) {
return eval("document.layers['" + a + "']")
} else {
return eval("document.all." + a)
}
}
};
this.SinaDotMarquee = function(id, h, s, d) {
var apthis = this;
var t;
var p = false;
var o = pthis.$(id);
o.style.overflow = "hidden";
o.style.height = h + "px";
o.style.lineHeight = h + "px";
o.innerHTML += o.innerHTML;
o.onmouseover = function() {
p = true
};
o.onmouseout = function() {
p = false
};
o.scrollTop = 0;
this.doScroll = function() {
try{
t = setInterval(apthis.scrolling, s);
if (!p) {
o.scrollTop += 2
}
}catch(e){}
};
this.scrolling = function() {
try{
if (o.scrollTop % h != 0) {
o.scrollTop += 2;
if (o.scrollTop >= o.scrollHeight / 2) {
o.scrollTop = 0
}
} else {
clearInterval(t);
setTimeout(apthis.doScroll, d)
}
}catch(e){}
};
setTimeout(apthis.doScroll, d)
};
try {
var SinaDotMarquee01 = new SinaDotMarquee("infan2010", 24, 20, 3000)
} catch(e) {}
})();
</script>
最终结果是jquery失效。贴这两段代码,应该可以了吧?
求高手帮忙解决。 展开
<script type="text/javascript" src="{URLROOT}/static/javascript/jquery.js"></script>
<script type="text/javascript">
(function() {
var pthis = this;
this.$ = function(a) {
if (document.getElementById) {
return eval('document.getElementById("' + a + '")')
} else {
if (document.layers) {
return eval("document.layers['" + a + "']")
} else {
return eval("document.all." + a)
}
}
};
this.SinaDotMarquee = function(id, h, s, d) {
var apthis = this;
var t;
var p = false;
var o = pthis.$(id);
o.style.overflow = "hidden";
o.style.height = h + "px";
o.style.lineHeight = h + "px";
o.innerHTML += o.innerHTML;
o.onmouseover = function() {
p = true
};
o.onmouseout = function() {
p = false
};
o.scrollTop = 0;
this.doScroll = function() {
try{
t = setInterval(apthis.scrolling, s);
if (!p) {
o.scrollTop += 2
}
}catch(e){}
};
this.scrolling = function() {
try{
if (o.scrollTop % h != 0) {
o.scrollTop += 2;
if (o.scrollTop >= o.scrollHeight / 2) {
o.scrollTop = 0
}
} else {
clearInterval(t);
setTimeout(apthis.doScroll, d)
}
}catch(e){}
};
setTimeout(apthis.doScroll, d)
};
try {
var SinaDotMarquee01 = new SinaDotMarquee("infan2010", 24, 20, 3000)
} catch(e) {}
})();
</script>
最终结果是jquery失效。贴这两段代码,应该可以了吧?
求高手帮忙解决。 展开
3个回答
展开全部
是$符号变量冲突了吧。你把你自己的JS代码里面的$变量换一个变量名呗。
<script type="text/javascript">
(function() {
var pthis = this;
this.$id = function(a) {
if (document.getElementById) {
return eval('document.getElementById("' + a + '")')
} else {
if (document.layers) {
return eval("document.layers['" + a + "']")
} else {
return eval("document.all." + a)
}
}
};
this.SinaDotMarquee = function(id, h, s, d) {
var apthis = this;
var t;
var p = false;
var o = pthis.$id(id);
o.style.overflow = "hidden";
o.style.height = h + "px";
o.style.lineHeight = h + "px";
o.innerHTML += o.innerHTML;
o.onmouseover = function() {
p = true
};
o.onmouseout = function() {
p = false
};
o.scrollTop = 0;
this.doScroll = function() {
try{
t = setInterval(apthis.scrolling, s);
if (!p) {
o.scrollTop += 2
}
}catch(e){}
};
this.scrolling = function() {
try{
if (o.scrollTop % h != 0) {
o.scrollTop += 2;
if (o.scrollTop >= o.scrollHeight / 2) {
o.scrollTop = 0
}
} else {
clearInterval(t);
setTimeout(apthis.doScroll, d)
}
}catch(e){}
};
setTimeout(apthis.doScroll, d)
};
try {
var SinaDotMarquee01 = new SinaDotMarquee("infan2010", 24, 20, 3000)
} catch(e) {}
})();
</script>
<script type="text/javascript">
(function() {
var pthis = this;
this.$id = function(a) {
if (document.getElementById) {
return eval('document.getElementById("' + a + '")')
} else {
if (document.layers) {
return eval("document.layers['" + a + "']")
} else {
return eval("document.all." + a)
}
}
};
this.SinaDotMarquee = function(id, h, s, d) {
var apthis = this;
var t;
var p = false;
var o = pthis.$id(id);
o.style.overflow = "hidden";
o.style.height = h + "px";
o.style.lineHeight = h + "px";
o.innerHTML += o.innerHTML;
o.onmouseover = function() {
p = true
};
o.onmouseout = function() {
p = false
};
o.scrollTop = 0;
this.doScroll = function() {
try{
t = setInterval(apthis.scrolling, s);
if (!p) {
o.scrollTop += 2
}
}catch(e){}
};
this.scrolling = function() {
try{
if (o.scrollTop % h != 0) {
o.scrollTop += 2;
if (o.scrollTop >= o.scrollHeight / 2) {
o.scrollTop = 0
}
} else {
clearInterval(t);
setTimeout(apthis.doScroll, d)
}
}catch(e){}
};
setTimeout(apthis.doScroll, d)
};
try {
var SinaDotMarquee01 = new SinaDotMarquee("infan2010", 24, 20, 3000)
} catch(e) {}
})();
</script>
追问
贴出来的js代码还是我的源代码,我对js不熟,代码是拿来用的,请问,这段代码应该怎么改呢?
追答
不知道你有没有仔细看,我把你的JS代码里面的$符号变量改成$id变量名。不在跟jQuery里面的$符号冲突了。哎。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
lz参考下jquery的多库共存机制
http://www.52ladybug.com/index.php/archives/238
this.$ = function(a) {}
应该是lz自定义的$和jquery的$符号有冲突了
http://www.52ladybug.com/index.php/archives/238
this.$ = function(a) {}
应该是lz自定义的$和jquery的$符号有冲突了
追问
我看了那解决冲突的3段代码,那请问,代码加在哪里用呢?
追答
//你自己的js定义$的东西
//jquery库文件
jQuery.noConflict();
jQuery(document).ready(function($){ //关键:闭包内使用$作为选择器(应该是个闭包吧。。)
// jquery相关代码块
$("div").hide();
});
$('someid').style.display = 'none';//其他代码块
具体的调用顺序:
自己定义$的地方---->jquery库----->释放jquery的$符号---->调用jquery闭包----->自己的非jquery相关代码块
参考资料: http://www.52ladybug.com/index.php/archives/238
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2011-09-05
展开全部
this.$ = function(a) 应该是$冲突了
追问
贴出来的js代码还是我的源代码,我对js不熟,代码是拿来用的,请问,这段代码应该怎么改呢?
追答
this.$ = function(a) 去掉 this.$ = 会有功能缺陷吗?!
或者像this.SinaDotMarquee = function(id, h, s, d) 明确指出
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |