我在html中有一个JavaScript。
这是:(对于我的网站滚动通知使用)。
<script>
JQ = $;
function JQ(element){
if(arguments.length>1){
for(var i=0,length=arguments.length,elements=[];i<length;i++){
elements.push(JQ(arguments[i]));
}
return elements;
}
if(typeof element=="string"){
return document.getElementById(element);
}else{
return element;
}
}
var Class={
create:function(){
return function(){
this.initialize.apply(this,arguments);
}
}
}
Function.prototype.bind=function(object){
var method=this;
return function(){
method.apply(object,arguments);
}
}
var Scroll=Class.create();
Scroll.prototype={
initialize:function(element,height){
this.element=JQ(element);
this.element.innerHTML+=this.element.innerHTML;
this.height=height;
this.maxHeight=this.element.scrollHeight/2;
this.counter=0;
this.scroll();
this.timer="";
this.element.onmouseover=this.stop.bind(this);
this.element.onmouseout=function(){this.timer=setTimeout(this.scroll.bind(this),1000);}.bind(this);
},
scroll:function(){
if(this.element.scrollTop<this.maxHeight){
this.element.scrollTop++;
this.counter++;
}else{
this.element.scrollTop=0;
this.counter=0;
}
if(this.counter<this.height){
this.timer=setTimeout(this.scroll.bind(this),22);
}else{
this.counter=0;
this.timer=setTimeout(this.scroll.bind(this),3126);
}
},
stop:function(){
clearTimeout(this.timer);
}
}
var myscroll=new Scroll("myscroll",13);
</script>
之后,我想为我的网站添加一个jquery函数,但是当我从googleapi中包含jquery时,它会与我的其他js冲突。我已搜索解决方案,添加类似jQuery.noConflict();
的内容,但它仍无法正常工作。
下面是我添加到html后的编码,有JS错误。下拉菜单都无法正常工作。
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
var jq = jQuery.noConflict();
jq(function(){
jq("#paysubmitbtn").click(function(){
if(jq("#paymount").val() >= $minco){
jq("#error").text("({lang jncashout:text_07}"+parseInt(jq("#paymount").val()*$exco*$jsuse)+"$jifentitle {lang jncashout:text_08}"+jq("#paymount").val()*$exco*$chargeco1+"$jifentitle {lang jncashout:text_09})");
}else{
jq("#error").text("({lang jncashout:text_10}"+$minco+"$cashoutname)");
return false;
}
});
});
jq(function(){
jq("#paymount").blur(function(){
if(jq("#paymount").val() >= $minco){
jq("#error").text("({lang jncashout:text_07}"+parseInt(jq("#paymount").val()*$exco*$jsuse)+"$jifentitle {lang jncashout:text_08}"+jq("#paymount").val()*$exco*$chargeco1+"$jifentitle {lang jncashout:text_09})");
}else{
jq("#error").text("({lang jncashout:text_10}"+$minco+"$cashoutname)");
}
});
});
</script>
我检查了谷歌Chrome控制台显示屏的错误
Uncaught TypeError: ctrlObj.getAttribute is not a function common.js?kkZ:1243
Uncaught TypeError: $(...).removeChild is not a function
Uncaught TypeError: ctrlObj.getAttribute is not a function
我在JS中真的不太好,请帮我解决我需要改进的问题,谢谢。
答案 0 :(得分:0)
我在您提供的代码段中看不到ctrlObj
。
但只是为了让您了解getAttribute()
javascript方法。
因此,如果ctrlObj
是一个jquery对象,它可能无法与getAttribute
一起使用。所以
在这种情况下,您可以使用jQuery .attr
方法。
实施例
var x = ctrlObj.attr(&#39;您的属性名称&#39;);