有什么办法可以找到它吗?例如:
var number=5;
$("#"+>number).remove();
Run Code Online (Sandbox Code Playgroud)
但我不知道如何做类似的事情,如果有可能:) 谢谢
$('div').filter(function() {
return parseInt( this.id, 10) > 5;
}).remove();
Run Code Online (Sandbox Code Playgroud)
如果id只包含number.
id。例如:
<div id="myid-5"></div>
<div id="myid-6"></div>
Run Code Online (Sandbox Code Playgroud)
并将上面的代码修改为:
$('div').filter(function() {
return parseInt( this.id.replace('myid-',''), 10) > 5;
}).remove();
Run Code Online (Sandbox Code Playgroud)