jqueryMobile加载相同的脚本两次

时间:2013-11-12 11:16:53

标签: javascript jquery asp.net-mvc-4 jquery-mobile

我有jquerymobile的问题。当我再次加载相同的页面时,脚本也会再次加载并且不起作用。我想只加载一次脚本。我使用jquerymobile 1.3.2和jquery 1.9.1。这是我的代码。

@using Entry.Net.Web.Model

<div data-role="page" class="jqm-demos ui-responsive-panel" id="table_page" "data-theme="a">

<div data-role="header" data-position="fixed">
        <a id="buttonObdobi" data-rel="popup" data-role="button" data-icon="grid" data-theme="a" data-position-to="window" data-transition="pop" data-inline="true">Období</a>
</div>

<div data-role="content">
    @*my content*@
</div>


<script type="text/javascript">
    $(document).on('pageinit', '#table_page', function () {
        Log.Info('$(document).on(pagecreate, #table_page)');

        $("#buttonObdobi").off("click").on("click", function () {
            Log.Info('buttonObdobi click');

            var model = $.parseJSON('@Html.Raw(Json.Encode(Model))');

            var popup = '<div data-role="popup" id="popupMenuObdobi" data-theme="c">' +
                            '<a id="closePopup" data-role="button" data-theme="a" data-icon="delete" data-iconpos="notext" class="ui-btn-right">Close</a>' +
                                '<ul id="ulObdobiTable" data-role="listview" data-inset="true" style="min-width: 210px;" data-theme="a">';
            $.each(model.ListObdobi, function (i, val) {
                popup += '<li><a id="' + val + '">' + val + '</a></li>';
            })
            popup += '</ul></div>';

            var popupafterclose = popupafterclose ? popupafterclose : function () { };

            $.mobile.activePage.append(popup).trigger("create");

            $.mobile.activePage.find("#closePopup").bind("tap", function (e) {
                $.mobile.activePage.find("#popupMenuObdobi").popup("close");
            });

            $.mobile.activePage.find("#popupMenuObdobi").popup().popup("open").bind({
               popupafterclose: function () {
                    Log.Info('bind popupafterclose');
                    $(this).unbind("popupafterclose").remove();
                    popupafterclose();
                }
            });


            $('#ulObdobiTable a').off('click').on('click', function () {
                $.mobile.changePage("#table_page", {
                    transition: "slide",
                    allowSamePageTransition: true,
                    data: { obdobi: $(this).attr('id'), ucet: '@Model.Account', type: '@Model.AccountType' }
                });
            });
        });

    });
</script>

你能告诉我我做错了什么吗?非常感谢你!

0 个答案:

没有答案