1

我有 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>

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

4

0 回答 0