我正在使用autoNumeric jQuery plugin 。我想让 .autoNumeric('set', value)
方法自动调用 .change()
事件。
我有以下代码:
$(document).ready(function ($) {
$("#baseCost").change(function() {
var total = ...; // calculation removed for code brevity
$("#totalCost").autoNumeric('set', total);
});
$("#totalCost").change(function() {
// this code does not fire when the set above is called
});
});
我该如何实现这个目标?
更新:在 autoNumeric.js 文件中,我找到了这个(在 set
内):
if ($input) {
return $this.val(value);
}
鉴于在我的情况下 $input 设置为 true,我不明白为什么这个 .val()
没有在我的设备上触发 .change()
页。
最佳答案
我没有意识到.val()
默认情况下不会触发.change()
。对于我的问题,以下代码在 autoNumeric.js 中实现了这一点:
if ($input) {
if ($this.val(value)) {
return $this.trigger("change");
}
return false;
}
有关详细信息,请参阅 this answer .
关于javascript - jQuery - autoNumeric 插件,自动从 .autoNumeric ('set' 触发 .change() ,值),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30784295/