js中splice方法,可以将元素从数组中移除,具体做法如下,(当然,这个方法功能很多,这里只列一种,做个笔记,有遇到的时候,再加上其它的。)
$("input[id*='ad']").change(function(){
if($(this).is(":checked")){
$("#seq").append("<span id='seq"+$(this).val()+"'> "+$("#span" + $(this).val()).html()+"</span>");
array.push($(this).val());
} else {
for(var i = 0; i < array.length; i++){
$("#seq"+$(this).val()).html("");
if(array[i] == $(this).val()){
//在该位置移除元素 ( items <- i -> items ) splice方法调用后,返回被移除元素的集合,即可从标记位置向两边Splice
array = array.slice(0,i).concat(array.slice(i+1,array.length));
}
}
}
});
});
//在该位置移除元素 ( items <- i -> items ) splice方法调用后,返回被移除元素的集合,即可从标记位置向两边Splice
上面这句话不知道大家懂不懂。。。反正我是懂了的。。