。在陣列當我<code>exist_id</code>數組值是<code>null</code>的<code>if</code>條件的作品並不if語句工作,在JavaScript
val = this.value
$(document).ready(function() {
$('.all_id_checkbox').click(function() {
var a = this.checked;
if (a == true) {
exist_id = new Array();
exist_id = <?php echo json_encode($exist); ?>;
val = parseInt(this.value);
if (jQuery.inArray(val, exist_id)) {
exist_error.push(val);
} else { }
}
});
});
什麼是'$ exist'的價值?或者更好 - 在輸出PHP之後,你的實際JS代碼是什麼?我猜想,'exist_id'將是一個對象,因此'$ .inArray'無效使用 –
'$(文件)。就緒(函數(){ $( 'all_id_checkbox')。點擊(函數( ){ VAR一個= this.checked; 變種VAL = parseInt函數(THIS.VALUE); 條件:(a == TRUE){ VAR exist_error = []; 變種exist_id =; 變種new_array = Object.values(exist_id); 如果(jQuery.inArray(VAL,new_array)){ exist_error.push(VAL); }否則{} } });} ) ;' –