我将一些数据动态绑定到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()
内的脚本仍然没有改变,我需要在我的dValue
中处理siPrifixx
,这需要人性化。但是我认为,我确实得到了价值,但是siPrifixx
没有被解雇。
答案 0 :(得分:1)
使用delegate
$('body').delegate('.widget-data','click',function() {
//Your scripts
});
答案 1 :(得分:1)
我找到了一种方法来调用它对我有用的功能。
$.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,
});
});
答案 2 :(得分:0)
使用on进行jquery
要监听的列表元素(此元素可以更改)
$(“table”)。on(“click”,“td”,function(){ //码 });