如何为动态html元素调用jquery插件?

How to call jquery plugging for dynamic html elements?

我正在将一些数据动态绑定到 html。当我绑定它时,我必须调用一个函数来处理相同 html 元素的值。见代码:

$.each(data, function(key, value) {
    htmlData += '<div class="large-1 infographic-box border_right merged-top pull-left widget-data" >';
          $.each(value,function(dKey,dValue){

                htmlData += '<span id="'+dKey+'['+ key +']"  class="'+dKey+' value widget-data" data-value="'+dValue+'">'+ dValue  +'</span>';
                })
                htmlData += '<span class="headline">'+ monthNames[parseInt(key)-1] +'</span>'+
                                 '</div>';
            });
                htmlData += '</div>';
                 $('.transaction-section').html(htmlData);
    $('.widget-data').each(function(){
            var value = $(this).data('value');
            var index = $(this).attr('id');
            $(this).siPrifixx(value,{
                maxDigits: 4,
                seperator: true,
                decimal: 1,
                popUp: true,
                countUp:index
           })
     });

为此 html 我必须在 $('.widget-data').each(function() 上调用一些函数。但是当我在里面/外面调用它时,块不会触发。我该怎么做?

我在 $(document).ready() 中的脚本,仍然没有得到改变,我需要在我的 siPrifixx 中处理 dValue,它需要 humanize.But 这个想法,我确实获得了价值,但 siPrifixx 没有被解雇。

使用delegate

$('body').delegate('.widget-data','click',function() {
     //Your scripts
});

使用on到jquery

  1. Select一个dom元素父亲(这个元素不能改变)
  2. 调用事件监听
  3. 要监听的列表元素(此元素可以更改)

    $( "table" ).on( "click", "td", 函数() { //代码 });

我找到了一种调用函数的方法,它对我有用。

$.each($(htmlData).find('.widget-data'), function(){
            var value = $(this).data('value');
            var index = $(this).attr('id');
            $(this).siPrifixx(value,{
                maxDigits: 4,
                seperator: true,
                decimal: 1,
                popUp: true,
            });
        });