在我的表單中,只是在從服務器加載後更改了已更改的值。對於我這樣做的功能:
$(checkBox).each(function(i,el){
status.push($(el).prop("checked"));
$(el).click(function(){
var clickedIndex = checkBox.index($(this));
var prevStatus = status[clickedIndex];
if(prevStatus !== $(this).prop("checked")){
statusChanged.push($(this).val() + ($(this).prop("checked") ? add.toLowerCase() : remove.toLowerCase()));
}else{
var that = $(this);
statusChanged = $.grep(statusChanged, function(value) {
return value != that.val() + add.toLowerCase()
});
statusChanged = $.grep(statusChanged, function(value) {
return value != that.val() + remove.toLowerCase()
});
}
console.log(statusChanged);
})
})
在此功能
,在其他部分(statusChanged)我打電話的$ .grep功能2倍"add"
和"remove"
- 的情況下,如果我寫這樣的功能(那一部分)
var that = $(this);
statusChanged = $.grep(statusChanged, function(value) {
return value != that.val() + add.toLowerCase() || that.val() + remove.toLowerCase() //not working
});
不工作..?這裏有什麼問題或$,grep不會接受或(||)三元運算符,或者任何一個給出其他簡短的方法..請提前致謝。