我想删除标签(card11,card3,card29 .... cardX)
var card_id = 11 ;
$("#card"+card_id).remove();
// ( maybe the card_id is 13, 19, 22 or 27...so it must be a variable)
我测试过这种方式
$("#card"+"11").remove();
它有效,但我希望它是一个变量。
答案 0 :(得分:0)
var cardIDs = [1, 2, 3];
for(var i = 0; i < cardIDs.length; i++) {
$('#card'+cardIDs[i]).remove();
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span id="card1">Card 1</span>
<span id="card2">Card 2</span>
<span id="card3">Card 3</span>
&#13;