【发布时间】:2013-02-10 22:38:58
【问题描述】:
我有一组由 ajax 调用 php 脚本生成的元素。
<tr id="rem[313]">...</tr>
<tr id="rem[345]">...</tr>
我的一个函数需要通过 id 删除某个 tr。
我已经尝试了所有方法,但似乎无法选择该死的东西
function remove_it(x){
$('#rem['+x+']').remove();
$(this).closest('tr').remove; // this i fire from the button click
}
测试我正在使用 .length 的选择,它都返回零
function remove_it(x){
alert($('#rem['+x+']').live().length;
alert($('#rem['+x+']').length);
alert($('#rem['+x+']').on().length);
}
【问题讨论】:
-
我支持大卫。特别是因为您使用双引号。或者使用单引号。
-
您可能需要考虑将该 id 添加到
data-*属性中。这将消除转义选择器内容的需要......您只需搜索$("tr[data-foo='"+ x +"']")。