文本框的值改变事件不被解雇的jQuery [英] textbox value change event not getting fired jquery
本文介绍了文本框的值改变事件不被解雇的jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我通过Ajax调用填充texbox值。我想改变的事件时得到价值得到填补解雇了。
I am filling texbox value through ajax call. i want to change event get fired when the value gets filled.
Ajax调用
$.ajax({
url: 'ajaxExecute.aspx/GetCustInfoTeller',
data: strRequest,
dataType: "json",
contentType: "application/json",
cache: false,
context: document.body,
type: 'POST',
success: function (response) {
var saResponse = response.d.split("|");
$('#txtDateofBirth').val(saResponse[0]); // For this textbox change event gets fired
}
});
$ C $下change事件处理
Code for change event handler
$("#txtDateofBirth").bind('change', function () {
alert('1');
var today = new Date();
var birthDate = new Date($("#txtDateofBirth").val());
var age = today.getFullYear() - birthDate.getFullYear();
var m = today.getMonth() - birthDate.getMonth();
if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
age--;
}
alert(age);
if (age > 7) {
$('#trMinor').hide();
}
else {
$('#trMinor').show();
}
});
我没有得到警告,当值输入 txtDateofBirth
通过AJAX
推荐答案
您必须触发事件手动,它才会自动如果变更是由用户界面启动触发。编程设定值不会触发变更
事件。
You have to trigger the event manually, it is only triggered automatically if the change was initiated by the user interface. Programmatically setting the value does not trigger the change
event.
您可以触发与 .trigger()
事件jQuery的方法:
You can trigger an event with the .trigger()
jQuery method:
$('#txtDateofBirth').val(saResponse[0]).trigger('change');
//or
$('#txtDateofBirth').val(saResponse[0]).change();
这篇关于文本框的值改变事件不被解雇的jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文