2013-01-14 47 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更換 $解決這個問題

它爲我工作。希望能幫助到你。