2013-01-14 49 views
-1

我使用jQuery来缩放图像,它工作正常,在试验html避免jQuery的confllict

但它显示的错误,看起来像冲突错误,当我尝试实施它在直播网站,其它JS也调用它,它显示下面的错误

Uncaught TypeError: Object #<HTMLDocument> has no method 'ready' * 1号线在base.js

我尝试下面的代码为避免冲突,但它不是作品看起来像我丢失了一些东西

jquery.noconflict(); 
$(document).ready(on_ready); 
function on_ready() { 
$('#search').defaultVal('search here...'); 
$('#comment').defaultVal('your comment here...'); 
$('#message').defaultVal('your message here...'); 
..... 

base.js文件可以下面提到链路

http://techchef.co/devTest/test/base.js

+0

尝试'jQuery'而不是'$'。如果你不调用jQuery.noconflict() – algorhythm

+0

刚刚阅读这个页面,你可以使用'$':http://api.jquery.com/jQuery.noConflict/ – algorhythm

回答

2
jQuery.noConflict(); 
// cannot use '$' because of .noConflict() 
// now the '$'-sign is free for other libraries e.b. MooTools... 
// ...that's what noConflict does 

// try using 'jQuery' instead of '$' here 
jQuery(document).ready(function() { 
    jQuery('.selector').click(function() { 
     // and so on 
    }); 
}); 

// or an other solution looks like this 

(function($) { 
    $(function() { 
     // more code using $ as alias to jQuery 
    }); 
})(jQuery) 

// in your case try 

jQuery(document).ready(function() { 
    // the code you have in your on_ready-function 
}); 

// or 

jQuery(document).ready(function() { 
    on_ready(); 
}); 
function on_ready() { 
    // your on_ready-function 
} 

MORE INFO

+0

当我试图做到这一点像它下面显示错误,和我在哪里调用它的通话 'jQuery.noConflict() jQuery的(文件)。就绪没有检测到函数调用的页面上(函数(on_ready){ 功能on_ready(){$ ( '#search')。defaultVal('search here ...'); $('#comment')。defaultVal('your comment here ...'); $('#message')。defaultVal('你的信息在这里......'); }); ' – mobi001

+0

实际上默认情况下,base.js调用** on_ready **函数,如下所示: '$(document).ready(on_ready); function on_ready(){ $('#search')。defaultVal('search here ...'); $('#comment')。defaultVal('your comment here ...'); $('#message')。defaultVal('your message here ...'); ' – mobi001

+0

好心指导我在这种情况下做什么 – mobi001

0
上看到

当我试图做到这一点像它下面显示错误,&不检测我在哪里默认base.js调用它的呼叫

jQuery.noConflict() 
jQuery(document).ready(function($) 
{ 
function on_ready() { $('#search').defaultVal('search here...');  
$('#comment').defaultVal('your comment here...'); 
$('#message').defaultVal('your message here...'); }); 

})

实际上在页面上的函数调用调用on_ready功能类似下面

$(document).ready(on_ready); 
function on_ready() { 
$('#search').defaultVal('search here...'); 
$('#comment').defaultVal('your comment here...'); 
$('#message').defaultVal('your message here...'); 
+0

嘿方法'defaultVal'不是jQuery函数。当您选择带有jQuery或'$'的DOM元素时,该对​​象会使用jQuery函数进行扩展。像往常一样,它是一个可以使用jQuery函数的数组。 'defaultVal'不是这样的函数,afaik'defaultVal'不是默认的javascript函数。如果你想改变一个jQuery元素的value属性,使用.val('value')作为函数。如果你想改变两个HTML标签之间的文本,使用.text()。看到这里http://api.jquery.com/text/和http://api.jquery.com/val/ – algorhythm

0

我只是在base.js

jQuery更换 $解决这个问题

它为我工作。希望能帮助到你。