JavaScript conflict with googleapi
JavaScript conflict with googleapi
我在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>
我从谷歌铬控制台显示检查错误
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方面真的不太好,请帮我解决我需要改进的问题,谢谢。
我在您提供的代码段中看不到ctrlObj
。
但只是为了让您了解getAttribute()
的javascript方法。
因此,如果ctrlObj
是一个jquery对象,那么它可能无法很好地与getAttribute
配合使用。所以在这种情况下,您可以使用jQuery .attr
方法。
示例
var x=ctrlObj.attr("您的属性名称");
相关文章:
- Fighting with FRP
- issue with FB.Event.subscribe
- geolocation-marker.js conflict with markerclusterer.js
- Angular 2.0 with JavaScript or TypeScript?
- 为什么不推荐使用“with”?是否有更好或其他方法可以“下降”到对象的命名空间
- WebComponentsJS with IE10
- 指令的模板必须只有一个根元素:With restrict E&替换true
- timeago.js with datatable and PHP
- Ajax and Json with Rails
- errors with Javascript try catch
- how to split a string with ','
- Understanding Javascript scope with "var that = this&qu
- Architecture for CPU intensive tasks with NodeJS & Socke
- How to declare a Map containing certain properties with flow
- 设置'这'在React with Inverse Data Flow中
- Unit-testing multiple use cases with Karma & Mocha.js
- Modify Javascript with C#
- 谷歌地图API v3:Initial View is Fine,but Gray Box with No Map if
- Using jQuery with classes from ES6
- JavaScript conflict with googleapi