<% (1..3).each do %>
<p id="input">
<input type="text" name="somename"/>
<a class="remove" >Remove</a>
</p>
<% end %>
jQuery:
var $remove=$(".remove")
$remove.click(
function(){
$(this).parent().remove();
alert($remove.length);
})
它总是提醒3
,为什么?我是否正确删除了类remove
?
最佳答案
从 DOM 中删除元素不会破坏 $remove
中保存的引用。尝试使用 alert($(".remove").length)
代替。
编辑: Here's a fiddle.
关于javascript - 当删除类时。类(class)长度没有变化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7768210/