0

这是我用于向表中添加新行的代码的一部分。我在编译与最后两个 TD 元素相关的代码时遇到问题。字符串文字总是存在错误。请帮我弄清楚。

$( "#content tbody" ).append( "<tr>" +
        "<td>" + opr.val() + "</td>" + 
        "<td>" + flightNum.val() + "</td>" + 
        "<td>" + from_f.val() + "</td>" +
        "<td id=" + flightNum.val() + " class='edit_but'>
          <div>
             <img src='images/edit.png' alt='Edit' />
          </div>
        </td>" +
        "<td id=" + flightNum.val() + " class='deact_but' onclick="deactivateRow('+flightNum.val()+')">
          <div>
             <img src='images/delete.png' alt='Deactivate' />
          </div>        
        </td>"  + "</tr>" ); 
4

2 回答 2

1
$( "#content tbody" ).append( "<tr><td>" + opr.val() + "</td><td>" + flightNum.val() + "</td><td>" + from_f.val() + "</td><td id=" + flightNum.val() + " class='edit_but'><div><img src='images/edit.png' alt='Edit' /></div></td><td id=" + flightNum.val() + " class='deact_but' onclick='deactivateRow(" + flightNum.val() + ")'><div><img src='images/delete.png' alt='Deactivate' /></div></td></tr>" );
于 2012-05-29T17:53:10.083 回答
-1

你的代码是一团糟!有很多引号(")丢失,字符串连接(+)丢失!

经过大量修复:

$( "#content tbody" ).append( "<tr>" +
        "<td>" + opr.val() + "</td>" + 
        "<td>" + flightNum.val() + "</td>" + 
        "<td>" + from_f.val() + "</td>" +
        "<td id=" + flightNum.val() + " class='edit_but'>" +
          "<div>" +
             "<img src='images/edit.png' alt='Edit' />" +
          "</div>" +
        "</td>" +
        "<td id=" + flightNum.val() + " class='deact_but' onclick='deactivateRow('" +flightNum.val()+")'>"  +
          "<div>" +
             "<img src='images/delete.png' alt='Deactivate' />" +
          "</div>"  +
        "</td></tr>" );​​​​​​​​​​​
于 2012-05-29T17:54:32.957 回答