第一個代碼段不起作用。不過,它開始工作時,$(美元符號)與jQuery(請參閱第二個片段)全部替換。但我真的不明白爲什麼?任何人都可以向我解釋這個嗎?非常感謝!
1日摘錄
jQuery.noConflict();
$(document).ready(function(){
$("#insideTable > tbody > tr:odd").addClass("odd");
$("#insideTable > tbody > tr:not(.odd)").hide();
$("#insideTable > tbody > tr:odd").show();
$("#insideTable > tbody > tr.odd").click(function(){
$(this).next().toggle();
$(this).find(".arrow").toggleClass("up");
});
});
第二個片段
jQuery.noConflict();
jQuery(document).ready(function(){
jQuery("#insideTable > tbody > tr:odd").addClass("odd");
jQuery("#insideTable > tbody > tr:not(.odd)").hide();
jQuery("#insideTable > tbody > tr:odd").show();
jQuery("#insideTable > tbody > tr.odd").click(function(){
jQuery(this).next().toggle();
jQuery(this).find(".arrow").toggleClass("up");
});
});
這就是答案! – trusktr
這是有效的,只是想指出傳遞給'ready'回調函數的第一個參數是jQuery對象,所以你可以在函數中使用'.ready(function($){'''),然後使用'''作爲只要你不需要使用外部$的東西。 – loganfsmyth