表中的定位按钮

时间:2014-12-19 05:29:30

标签: javascript jquery html

我动态创建一个表格行,如下所示,使用"删除"最后一个表格单元格内的按钮,但是在渲染时,“删除”按钮并没有整齐地放在桌子所在的位置。有什么想法吗?

    strAppend = '<tr>' +
                    '<td id="SUBJ_'+idNum+'" class="td-SUBJ_'+idNum+'"><input type="text" class="SUBJ" value="Elective" name="SUBJ"> </td>' +
                    '<td id="REQUIRED_'+idNum+'" class="td-REQUIRED"><input type="checkbox" value="1" maxlength="40"> </td>' +
                    '<td id="DELETED_'+idNum+'" class="td-DELETED"><button id="DELETE_"'+idNum+'" class="DELETE">Del</button></td>' +
                    '<td><input value="Test"></td>' +
                '</tr>'

    //Add row
    $j("tbody > tr:last").prev().before(strAppend);

1 个答案:

答案 0 :(得分:2)

您过早关闭报价

'<td id="DELETED_'+idNum+'" class="td-DELETED"><button id="DELETE_"'+idNum+'" class="DELETE">Del</button></td>' +

会导致类似这样的事情

<td id="DELETED_5" class="td-DELETED"><button id="DELETE_"5" class="DELETE">Del</button></td>

删除按钮定义中的额外引用

'<td id="DELETED_'+idNum+'" class="td-DELETED"><button id="DELETE_'+idNum+'" class="DELETE">Del</button></td>' +