基金会揭示附加内容

时间:2013-06-05 20:24:57

标签: jquery html

我通过.append将一些内容加载到未排序的列表元素中,如下所示:

    $(document).ready(function(){
        $("#player_status_5342").html('<img src=" /site/templates/images/system/loader/small_ajax_loader.gif"/>');
        $.getJSON("/api-checks/get_ingame_bool/euw/rorotan", function(result){
        console.log(result + " RoroTan");
            if(result == '1'){
                $("#player_status_5342").html('<img src=" /site/templates/images/system/status/online.png"/>');
                $("#36868417").append('<li><a href="/pages/ingame-info/euw/RoroTan" class="modal" reveal-size="large">See game details!</a></li>');
            }else{
                $("#player_status_5342").html('<img src=" /site/templates/images/system/status/offline.png"/>');
            }
        });
    });

player_status_5342是一个范围。

这就是我之前使用click事件的方式:

$(document).ready(function(){
    $(function(){
        $(document).foundation();    
    })
    $('a.modal').click(function(event) {
        event.preventDefault(); //Prevent default event
        var size = $(this).attr('reveal-size');
        var $div = $('<div id="modal">'),$this = $(this);
        $('#modal').each(function(){//Clean added classes - for repeated loads
            $(this).remove();
        });
        $div.addClass('reveal-modal '+size).appendTo('body');//Add reveal to body

        $div.empty().html('<p align="center"><img src="http://www.kadowereld.nl/images/algemeen/loader2.gif" /></p>').append('<a class="close-reveal-modal">&#215;</a>').foundation('reveal', 'open');//Create reveal with Preloader!

        $.get($this.attr('href'), function(data) {
            return $div.empty().html(data).append('<a class="close-reveal-modal">&#215;</a>').foundation('reveal');//Add ajax data to preloadr. W can use jquery $.post also.
        });
    });
});

我已经尝试过使用.on(&#34;点击&#34;,功能(){

因为这通常解决了我的问题,但这次没有用。

2 个答案:

答案 0 :(得分:2)

不是

$('a.modal').on('click', function(){})

$(document).on('click', 'a.modal', function(){})

document是最接近的非动态父级。

答案 1 :(得分:0)

Johnvh说明了这种解决方法;在尝试调用open之前初始化窗口小部件。

以下作品:

  $('<div></div>')
  .addClass('reveal-modal')
  .attr('data-reveal', '')
  .append($('<h1>Hello</h1>'))
  .appendTo($('body'))
  .foundation('reveal')     // <-- need this first!
  .foundation('reveal', 'open');