【问题标题】:Split long string constant in multiple lines在多行中拆分长字符串常量
【发布时间】:2014-02-06 05:14:36
【问题描述】:

我写了下面的命令,生成一个数据网格,它工作正常没有问题,但是命令很长,如果我使用 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>');

【问题讨论】:

  • 向我们展示您的故障尝试和错误
  • 任何理解 JavaScript 的文本编辑器都应该可以做到。像 VS + R#...
  • 您可以在代码中的 + 符号后添加新行。要在其他地方插入新行,你必须这样做:part1 + part2 + part3 + ....

标签: javascript


【解决方案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>'......

【讨论】:

  • +1,但你真的不应该在你的 smaple 样式中使用这么错误的地方(与 CSS 相比)。 calss="GoodClassName" 更适合 SO...
  • @AlexeiLevenkov 是的,谢谢,我只是一个新开发者:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-29
  • 1970-01-01
  • 2016-07-03
  • 2014-06-19
  • 2021-10-24
相关资源
最近更新 更多