我正在使用autoNumeric jQuery插件。我想让.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()。
发布于 2015-06-11 15:03:50
我没有意识到.val()默认不会触发.change()。对于我的具体问题,在autoNumeric.js中有以下技巧:
if ($input) {
if ($this.val(value)) {
return $this.trigger("change");
}
return false;
}有关更多信息,请参见这个答案。
https://stackoverflow.com/questions/30784295
复制相似问题