jquery关于事件没有在phonegap工作,但铬工作正常

时间:2014-02-07 10:36:21

标签: javascript jquery cordova

jquery on 事件不适用于在phonegap上准备好文档后追加的类。但它在chrome上运行良好。

我的模板代码在这里:

    <script type="text/template" id="newsList">
        <div class="news-list" news_id="{3}">
            <div class="news-list-title">
                <span>{0}</span> | {1}
            </div>
            <div class="news-list-text">{2}</div>
            <span class="news-list-more">Oku</span>
        </div>
    </script>

渲染方法:

    var template = $("#newsList").html();
    var str = "";
    for(var i in data[page]){
        str += template.format(data[page][i]['created_at'], data[page][i]['title'], data[page][i]['content'], data[page][i]['id']);
    }
    $("#news-list-wrapper").html(str);

和事件代码:

    var app = {
        initalize: function(){
            var _this = this;
            $(document).on("click", ".news-list", function(){
                _this.openNews($(this).attr("news_id"));
            });
        }
    }


    $(document).ready(function(){
        document.addEventListener("deviceready",function(){
            app.initialize();
        },false);
    });

我的jquery版本是1.9.1,我试过2.1.0

我试过这些;

    $(document).on("click", ".news-list", function(){....
    $(".news-list").on("click", function(){....
    $(document).delegate("click", ".news-list", function(){....
    $(".news-list").live("click", function(){....

0 个答案:

没有答案