我的代碼加載最需要被加載,以便其他的代碼之前,它才能正常工作。爲了讓我實現這個目標,我一次又一次地使用了多個腳本。有沒有辦法可以清理這些?我將盡力並給予例子:試圖鞏固jQuery代碼
//This needs to load first to add class
<script>
$(function(){
if (typeof(global_Current_ProductCode) !="undefined")
{
if ($('#pt494').length == 0)
{ $('font[class="text colors_text"]:eq(0)').closest('table').addClass('thePrices'); }
}
});
</script>
//This needs to load 2nd because it has to add the class first before it does this
<script>
$(function(){
if (typeof(global_Current_ProductCode) !="undefined")
{
if ($('#pt490').length == 0)
{ $('table[class="thePrices"]:eq(0)').closest('table').before($('font[class="productnamecolorLARGE colors_productname"]:eq(0)').addClass('toptitle'));}
}
});
</script>
有這麼多的代碼與此類似,也一定是把它扔到都在相同的IF語句的方法嗎?
嗯,只是將它們放入同一'$(函數())'彼此下方(甚至下方彼此在同一個if語句)應該足夠了。或者我誤解了你的問題? – 2011-06-16 21:02:45
沒有根據我有限的DOM樹的知識,它是一個非常基本的問題if語句= P – ToddN 2011-06-16 21:06:30