我有大量代码需要在另一段代码之前加载,以使其正常工作。为了让我实现这一点,我一遍又一遍地编写了多个脚本。有什么办法可以清理一些吗?我将尝试举例:
//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 语句下吗?