有一個項目名稱和某些按鈕,如新建,編輯和刪除表。 現在點擊這些按鈕,它會打開一個獲取信息的模式,並在其中有一個提交按鈕以保存數據庫中的更改。如何防止模態打開時文檔中輸入鍵的keydown事件?
我在開關時的keydown事件這個文件,該文件顯示在下一頁的高亮項行的進一步細節回車鍵。
所以會發生什麼情況是當模式打開,我迅速通過標籤按鈕焦點提交按鈕,然後單擊該焦點按鈕上的輸入,該項目被提交,但直接下一頁打開與選定的項目細節我不想要。
我想,當模式是開放的,應防止文檔的keydown事件(ie.should不工作),我應該能夠提交模式。
我想這很清楚,我想要什麼。所以,如果他們是一個擺脫它,那麼請幫助我。您的幫助將不勝感激。
下面是代碼更好地理解它..
$(document).keydown(function(e){
switch(e.which){
/* Enter Key */
case 13:
if(localStorage.check_submit != 1){
location.assign('estimate_partyitems.php'); */
break;
}
}
/* End of Switch Case */
});
/* End of Keydown Event */
$("#btn_new").on("click", function(){
$('#newestimate_modal').on('shown.bs.modal', function() {
// some code
localStorage.check_submit = 1;
});
$('#newestimate_modal').on('hidden.bs.modal', function (e) {
// some code
localStorage.check_submit = 0;
});
/* On Adding the New Estimate */
$('#newestimate_form').submit(function(event){
/*
preventDefault method cancels the event if it is cancelable
Here it is used to prevent the form from submitting.
*/
event.preventDefault();
// some code and ajax requests
/* unbind() method removes event handlers from selected elements. */
$("#newestimate_form").unbind('submit');
});
});
你爲什麼標記「全部」標籤? – Andreas