【问题标题】:json2html, I need to add click events to the resulting htmljson2html,我需要在生成的 html 中添加点击事件
【发布时间】:2014-02-05 14:55:23
【问题描述】:

json2html,我需要在转换后将点击事件添加到生成的 html 中。现在我正在使用计时器。即使它似乎不是一个选项,我也尝试将代码添加到转换调用的选项中。没用。有没有比向 document.ready 添加计时器更好的选择,以便在将我的点击事件添加到结果 div 之前运行转换时间?

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

【问题讨论】:

    标签: javascript jquery html fancybox json2html


    【解决方案1】:

    这个答案来得有点晚了..但迟到总比没有好。

    你可以像这样直接在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;
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-05-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-16
      • 1970-01-01
      • 1970-01-01
      • 2015-06-06
      相关资源
      最近更新 更多