禁用的文本框更改事件 [英] Disabled textbox change event
问题描述
简短说明
每当禁用的文本框值更改时,我都想做些事情
I want to do something whenever disabled textbox value is changed
详细说明
我有一个禁用的文本框,该值是通过编程方式设置的,我想绑定禁用的文本框的change事件以触发其他功能.这是我尝试过的方法,但是不起作用.
I have a disabled text box which value is setting programitically I want to bind the change event of disabled textbox to fire some other function. This is what I tried but won't work.
$('#Rate').change(function() {
// alert("Change Event Called");
CalculateMedicine();
});
$('input[id$=Rate]').bind("change", function () {
CalculateMedicine();
});
这对我来说都不起作用,我也不喜欢将函数CalculateMedicine()
放置到可能更改Rate
文本框的所有位置的想法.因此,除了此解决方案之外,任何帮助都将被赞赏
This both thing don't work for me and the I don't like the idea to put a function CalculateMedicine()
to all the place from which possibly Rate
textbox is changing.So apart from this solution any help will be appreciated
推荐答案
如果您以编程方式更改值,则不会触发change
事件
The change
event will not fire if you change the value programmatically
请参见 https://stackoverflow.com/a/7878081/3052648
一个不优雅的可能解决方案:
function checkChanges(){
if(prevRate != $('#Rate').val()){
prevRate = $('#Rate').val();
alert('changed');
}
}
var prevRate;
$(document).ready(function(){
prevRate = $('#Rate').val();
setInterval(function(){
checkChanges();
} ,500);
});
这篇关于禁用的文本框更改事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!