2014-02-05 51 views
2

json2html,我需要在转换后将点击事件添加到生成的html。现在我正在使用计时器。即使它看起来不是我想要将代码添加到变换调用的选项的选项。没有工作。有没有比添加计时器到document.ready更好的选择,以便在将单击事件添加到所生成的div之前为转换时间运行?json2html,我需要将点击事件添加到生成的html

setTimeout(function() { 
    $('.item').click(function() { 
    $this = $(this); 
    $.fancybox({ 
     height: '100%', 
     href: $this.find('a').attr('href'), 
     type: 'iframe', 
     width: '600px' 
    }); 
    return false; 
    }); 
}, 1000); 

回答

2

这个答案有点晚了..但是嘿,迟到比从未。

可以直接给json2html内的事件,像这样

json2html eventData example

或者你可以以后你只是做手工调用变换像这样

$('#someElement).json2html(data,transform); 

$('.item').click(function() { 
    $this = $(this); 
    $.fancybox({ 
     height: '100%', 
     href: $this.find('a').attr('href'), 
     type: 'iframe', 
     width: '600px' 
    }); 
    return false; 
}); 
相关问题