在多行中拆分长字符串常量

时间:2014-01-17 01:34:53

标签: javascript

我已经编写了bellow命令,生成一个数据网格,它运行正常没有问题,但命令太长了,如果我使用enter将命令分解为不同的行,jquery命令将会出错并且不会回应。

有没有办法打破这个长命令?

       $("#mainholder ul").append('<li><p><table><th  id="contentWrapper"><font size="+2" face="Gotham, Helvetica Neue, Helvetica, Arial, sans-serif" style="font-weight:bold" color="#FF0000">'+poId+'</font></th><th  id="contentWrapper"><img src="../images/products/iPhone.png" width="80" height="80"/></th><th  class="itSt"><font color="#FF0000" >'+itStat+'</font></th><th id="contentWrapper"><table><tr><td class = "tdinfo"><lable class="titleCs">Price : </label><input id="'+usId+'<seperator>'+orId+'<seperator>'+poId+'"  class="contentInput" onClick="priceClk(this.id)"></td></tr><tr><td class = "tdinfo"><lable class="titleCs">Quantity : </label><input id="'+usId+'<seperator>'+orId+'<seperator>'+poId+'"  class="contentInput" onClick="qtyClk(this.id)"></td></tr><tr><td class = "tdinfo"><lable class="titleCs">Express : </label><input id="'+usId+'<seperator>'+orId+'<seperator>'+poId+'"  class="contentInput" onClick="expClk(this.id)"></td></tr></table></th><th id="contentWrapper"><table><tr><td><textarea id="'+usId+'<seperator>'+orId+'<seperator>'+poId+'" onClick="offDesc()" class="commentBox"></textarea></td></tr></table></th> <th id="contentWrapper"><table><tr><td><textarea id="'+usId+'<seperator>'+orId+'<seperator>'+poId+'" onClick="yorDesc()" class="commentBox"></textarea></td></tr></table></th>     <th id="contentWrapper"><table><tr><td> <img class="css-checkbox" src="../images/deleteIcon.png" width="20" height="20"  alt=""/></td></tr><tr><td><input id="" class="css-checkbox" type="checkbox" /></td></tr></table></th></table></div></p></li>');

1 个答案:

答案 0 :(得分:1)

使用\换行。

$("#mainholder ul").append(
    '<li><p><table>\
     <th  id="contentWrapper">\
     <font\
         size="+2"\
         face="Gotham, Helvetica Neue, Helvetica, Arial, sans-serif"\
         style="font-weight:bold"\
         color="#FF0000">'+poId+'</font>'......