永发信息网

求问,做的网页这两个js冲突怎么解决?不能同时运行~求解决方案,谢谢

答案:2  悬赏:20  手机版
解决时间 2021-03-11 01:22
  • 提问者网友:浮克旳回音
  • 2021-03-10 14:32
第一个:function jQuery(id) { return document.getElementById(id); }
function addLoadEvent(func){
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function(){
oldonload();
func();
}
}
}
function moveElement(elementID,final_x,final_y,interval) {
if (!document.getElementById) return false;
if (!document.getElementById(elementID)) return false;
var elem = document.getElementById(elementID);
if (elem.movement) {
clearTimeout(elem.movement);
}
if (!elem.style.left) {
elem.style.left = "0px";
}
if (!elem.style.top) {
elem.style.top = "0px";
}
var xpos = parseInt(elem.style.left);
var ypos = parseInt(elem.style.top);
if (xpos == final_x && ypos == final_y) {
return true;
}
if (xpos < final_x) {
var dist = Math.ceil((final_x - xpos)/10);
xpos = xpos + dist;
}
if (xpos > final_x) {
var dist = Math.ceil((xpos - final_x)/10);
xpos = xpos - dist;
}
第二个:(function(){

var

window = this,

undefined,

_jQuery = window.jQuery,

_$ = window.$,

jQuery = window.jQuery = window.$ = function( selector, context ) {

return new jQuery.fn.init( selector, context );
},

jQuery.fn = jQuery.prototype = {
init: function( selector, context ) {

selector = selector || document;
if ( selector.nodeType ) {
this[0] = selector;
this.length = 1;
this.context = selector;
return this;
}
太长了放个开头吧
最佳答案
  • 五星知识达人网友:何以畏孤独
  • 2021-03-10 15:47
第二个貌似是jquery源码,
function jQuery(id) { return document.getElementById(id); }
这个方法是自己写的吧,如果是,不要用jQuery 做方法名
全部回答
  • 1楼网友:逐風
  • 2021-03-10 16:20
你干嘛要把jquery选择器的代码扒了几段?jquery整个引用不是很好? 你定义的这一段function jQuery(id) { return document.getElementById(id); } 这句相当于把jQuery定义成了一个只能做id选择器的函数 而又把jquery定义成了一个jquery标准的选择器,会把第一个的值覆盖掉,于是你id选择器就用不了了,只能用传入对象的选择器
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯