[英]How can I show alert message if input box content is changed and button is not pressed?
我有一個textarea框來顯示來自db的注釋。 此框數據使用以下submit
按鈕保存:
<button class="submit" id="save_note" value="save_note" onclick="edit_notebox(this,event);"><b>Save Note</b></button>
現在,如果所有以下條件都滿足,我將嘗試顯示警報消息:
如果以上3個條件為真或滿足,則我想顯示警報消息。
因此,為此,我正在使用以下代碼,但無法正常工作:
Js代碼:
var is_clicked = $("#save_note").val();
var previousValue = $("#project_notes").val();
$("#project_notes").blur(function(e) {
var currentValue = $(this).val();
if( currentValue != previousValue && is_clicked != 'save_note' ) {
previousValue = currentValue;
alert("Value changed!");
}
});
如何根據以上3種情況獲得警報消息?
您可以使用布爾變量沿這些方式執行一些操作:
var is_clicked = false;
var previousValue = $("#project_notes").val();
// Use mousedown instead of click so that it fires before the blur
$('.submit').on('mousedown', function(){
is_clicked = true; // Click happened
});
$("#project_notes").blur(function(e) {
var currentValue = $(this).val();
if (currentValue != previousValue && !is_clicked) {
previousValue = currentValue;
alert("Value changed!");
}
is_clicked = false; // Reset to catch next button click
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.