0
兩個不同的警報如果我使用的分配時通知他們並沒有輸入金額用戶的onbeforeunload jQuery的事件沒有輸入charge_amt輸入框的值。他們輸入金額後可以保存。我在頁面上有兩個按鈕,保存並完成。我找了兩個輸入字段
<td><input type="hidden" name="charge_cc" value="0" class="">
<input type="checkbox" id="charge_cc" name="charge_cc" value="1" checked="" class=""> Charge CC? Amount $ <input type="text" id="charge_amt" name="charge_amt" value="523" size="8" maxlength="6"></td>
<script>
$(document).ready(function(){
$("input[type='text'], select, textarea").change(function(){
window.onbeforeunload = function()
{
return "You have not saved an amount to be charged.";
}
});
$("charge_amt").submit(function(){
window.onbeforeunload = null;
});
});
</script>
第二個事件是完整的按鈕。
<input type='checkbox' name='reorder_comment_for_CC'> Verify Charge and Leave Comment" ?>
如果他們去打完成,但該複選框沒有被標記我想提醒他們,他們將無法未經覈實/檢查完成事件。
也許我應該只使用兩個獨立的事件,就像這樣:
<script type="text/javascript">
$("#charge_amt").keypress(function() {
if($(this).val().length > 1) {
return "You have not input an amount to be charged.";
} else {
return "Thank you for entering a charge amount, you can now save.";
}
});</script>