我的代码加载最需要被加载,以便其他的代码之前,它才能正常工作。为了让我实现这个目标,我一次又一次地使用了多个脚本。有没有办法可以清理这些?我将尽力并给予例子:试图巩固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