jQuery更改事件只触发一次-editableTableWidget和autoNumeric插件

jQuery更改事件只触发一次-editableTableWidget和autoNumeric插件,jquery,onchange,Jquery,Onchange,我使用两个插件:和。 第一个用于设置货币格式,第二个用于让用户编辑表格。 我需要合并它们,这样当用户编辑表时,货币会自动格式化 问题是,如果我在货币未格式化时多次尝试编辑,则对于ID为import的每个单元格,仅触发一次更改事件 那是我的HTML <table id="preview"> <tbody> <tr> <td id="date"></td> <td id="description"></td

我使用两个插件:和。 第一个用于设置货币格式,第二个用于让用户编辑表格。 我需要合并它们,这样当用户编辑表时,货币会自动格式化

问题是,如果我在货币未格式化时多次尝试编辑,则对于ID为import的每个单元格,仅触发一次更改事件

那是我的HTML

<table id="preview">
<tbody>
  <tr>
   <td id="date"></td>
   <td id="description"></td>
   <td id="import"></td>
   <th id="total"></th> --> NOT EDITABLE
</tr>
  <tr>
   <td id="date"></td>
   <td id="description"></td>
   <td id="import"></td>
   <th id="total"></th> --> NOT EDITABLE
</tr>
  <tr>
   <td id="date"></td>
   <td id="description"></td>
   <td id="import"></td>
   <th id="total"></th> --> NOT EDITABLE
</tr>
</tbody>
</table>
我也读了这些帖子:


    • 我不知道这是否是最好的解决方案,但它确实有效。 在用“init”初始化autoNumeric,然后像这样“update”之前:

      $('#preview').editableTableWidget().tableFormat().find('tbody').focus();
      $.fn.tableFormat = function () {        
          'use strict';
          var element = $(this)
          element.find('td').on('change', function () {
          $(this).autoNumeric('init', {aSep: '.', aDec: ','});
          if ($(this).is("#import")) {
                  $(this).autoNumeric('update', {aSep: '.', aDec: ','});
                  return;
              } 
          })
          return this;
      };
      

      将对象集的类用作选择器,而不是id。仅在第一个id上响应是预期行为。使用类…不能同时使用类
      $('#preview').editableTableWidget().tableFormat().find('tbody').focus();
      $.fn.tableFormat = function () {        
          'use strict';
          var element = $(this)
          element.find('td').on('change', function () {
          $(this).autoNumeric('init', {aSep: '.', aDec: ','});
          if ($(this).is("#import")) {
                  $(this).autoNumeric('update', {aSep: '.', aDec: ','});
                  return;
              } 
          })
          return this;
      };