[英]How to verify that input field has changed in jQuery
The method I wrote checks if the date has inserted/changed in input field, and I want to trig confirm message to the user when this condition is true. 我写的方法检查日期是否在输入字段中插入/更改,并且当此条件为真时,我想向用户触发确认消息。 The problem that the confirm message is triggered every time even when the date has not changed.
即使日期未更改,每次也会触发确认消息的问题。 My method looks like below:
我的方法如下所示:
var alertuserSave = function() {
val4 = $("#ContentPlaceHolder1_txtFinalized").val();
var alrt_value = document.createElement("INPUT");
alrt_value.type = "hidden";
alrt_value.name = "confirm_value";
if ((val3 === "5" || val3 === "6") && val4) {
confirm("Remember to Save the inserted data.");
alrt_value.value = "Yes";
} else {
alrt_value.value = "No";
}
document.forms[0].appendChild(alrt_value);
}
And I added a listener on document load like this: 我在文档加载中添加了一个侦听器,如下所示:
var val3 = $('#ContentPlaceHolder1_ddlResponsibility').val();
var val4 = $("#ContentPlaceHolder1_txtFinalized").val();
console.log(val4 + " is val4 ")
$(document).ready(function() {
$("#ContentPlaceHolder1_txtFinalized").change(alertuserSave);
How to make the pop up fired only when the date has changed and not every time? 如何仅在日期更改而不是每次更改时才触发弹出窗口?
val4 = $("#ContentPlaceHolder1_txtFinalized").val();
returns the value of the element 返回元素的值
so if you check: 因此,如果您检查:
(... && val4)
it is always true 永远是真的
you need to check something like: 您需要检查以下内容:
val4 != oldvalue
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.