假设我有下面的代码:
textInput = $('#outputTextInput').val();
$('#outputAdd').click(function(){
$('#status_table tr:last').after('<tr id="output_newrow_"+textInput><td>1</td><td id="type_row_"+textInput>lala</td><td id="num_row_"+textInput>num row '+textInput+'</td><td><img class="image" src="static/OffLamp-icon.png" style="height:64px; width=64px"/></td></tr>');
});
$('#outputRemove').click(function(){
$('#status_table').find("#output_newrow_"+textInput).remove();
});
然后我想用 ID“output_newrow_”+textInput 或“type_row_”+textInput 调用该选择器,这样......
$('#how_should_i_write_it_here').append(textInput)
我不知道应该如何调用该选择器......
预先感谢您的所有帮助:)
更新!这里是Fiddle http://jsfiddle.net/yvonnezoe/KGcrf/1/关联。我现在的问题是,我无法显示变量“textInput”,并且当我添加和删除几次时索引号很乱。例如,我键入“1,2,3”,它将在表格上显示索引2,3,4。但是当我输入 3 并单击“删除”时,它会删除索引 2(假设链接到 1)。
您的代码中的字符串连接是错误的,在您的代码中也是错误的index
is undefined
.
$('#outputAdd').click(function(){
var textInput = $('#outputTextInput').val();
var str = '<tr id="output_newrow_' +textInput + '">'
+ '<td>1</td><td id="type_row_' + textInput '">lala</td>'
+ '<td id="num_row_' + textInput + '">num row ' + textInput + '</td>'
+ '<td><img class="image" src="static/OffLamp-icon.png" style="height:64px; width=64px"/></td>'
+ '</tr>';
$('#status_table tr:last').after(str);
});
$('#outputRemove').click(function(){
$("#output_newrow_"+textInput).remove();
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)