我有一个列表,我使用jQuery来允许删除list对象。
$(document).off('click', '#delete').on('click', '#delete',function(e) {
$(this).parent().remove();
}); 我想知道如何判断被删除的元素是否是列表中的第一个元素?
发布于 2014-06-23 15:02:31
您还可以使用.index()位置。此函数返回一个基于零的索引,因此,对于第一个元素,您将得到0。另一个有趣的问题是,在javascript中,0是false,所有其他数字都是true。然后,如果元素是第一个元素,则.index()函数返回false。
$(document).off('click', '#delete').on('click', '#delete',function(e) {
if(!$(this).parent().index()){
//the element is the first element
}
});发布于 2014-06-23 14:57:53
发布于 2014-06-23 14:58:11
https://stackoverflow.com/questions/24369055
复制相似问题