我有以下輸入字段:的jQuery - 添加例外的onclick
<input type="text" value="5" maxlength="12" id="qty" class="input-text qty" name="qty2050" tabindex="1">
和
<input type="text" value="0" maxlength="12" id="qty" class="input-text qty" name="qty2042" tabindex="1">
我用這個代碼,以防止用戶丟失插入的數據(在退出頁面):
<script>
window.onbeforeunload = function() {
var showAlert = false;
jQuery('.input-text.qty').each(function(){
//console.log("fonction 1");
var val = parseInt(jQuery(this).val(),10);
if(val > 0) { showAlert = true; }
//alert(val);
});
//console.log("fonction 2");
//console.log(showAlert);
if (showAlert == true) {
console.log("fonction 3");
return 'You have unsaved changes!';
}
}
</script>
我想添加一個異常到我的提交按鈕,並且當數量大於0的時候不顯示警告消息我的輸入字段。
我的問題是添加此異常!
感謝您的幫助。
也許提供一些你想要的幫助信息? – Jivings
我編輯了我的問題,我希望現在更清楚... – Bizboss
什麼是數量> 0,你說什麼警報,也許嘗試清理你的問題... – Nayish