簡體   English   中英

jQuery-autoNumeric插件,從.autoNumeric('set',value)自動觸發.change()

[英]jQuery - autoNumeric plugin, fire .change() automatically from .autoNumeric('set', value)

我正在使用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()

我沒有意識到默認情況下.val()不會觸發.change() 對於我的問題,以下是autoNumeric.js中的技巧:

if ($input) {
    if ($this.val(value)) {
        return $this.trigger("change");
    }
    return false;
}

有關更多信息,請參見此答案

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM