更改页面时出现问题

更改页面时出现问题

本文介绍了jQuery Mobile,更改页面时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的jquery移动网站内部,我从页脚textinput请求发送到控制器,该控制器将json数据作为弹出窗口发送回视图(此弹出窗口内的数据使用jstemplate呈现).

Inside my jquery mobile website I'm sending from footer textinput request to the controller which sends back json data back to the view as popup window (data inside this popup window is rendered using jstemplate).

一切正常,但是当我更改页面请求时,请求被传递给控制器​​,但没有显示弹出窗口.

Everything works as expected but when I change page request is passed to the controller but popup window not showing.

我正在从js函数发送

 $("#myDataPopUp").popup("open").enhanceWithin();

和_Layout.cshtml内

and inside _Layout.cshtml

<div id="myDataPopUp" data-role="popup" class="ui-content" data-theme="a" />

同样,一切正常,直到我更改页面为止(因为代码位于_Layout内),它也应该可以在其他页面上使用.

Again, everything works fine until I change page (since code is inside _Layout) it should work on other pages as well.

推荐答案

由于您使用的是jQuery Mobile 1.4,因此我建议您使用外部弹出窗口,该页面可以从任何页面访问. 外部弹出窗口应放置在任何页面 div data-role="page"的外部,然后应手动初始化.

Since you're using jQuery Mobile 1.4, I do recommend using External Popup which can be accessed from any page. An External Popup should be placed outside any page div data-role="page" and then it should be initialized manually.

<div data-role="popup">
  <!-- contents -->
</div>

<div data-role="page">
  <!-- contents -->
</div>

初始化外部弹出窗口:

如果弹出窗口包含其他 jQM小部件,则还需要通过调用.enhanceWithin() 初始化这些小部件.否则,.popup()就足够了.

Initialize External Popup:

If the Popup contains other jQM widgets, you need to initialize those widgets as well by calling .enhanceWithin(). Otherwise, .popup() is enough.

$(function () {
  $("#popupID").popup().enhanceWithin();
});

打开/关闭弹出窗口:

  • 动态

    Open/Close Popup:

    • Dynamically

      /* to enhance jQM widgets inside popup, if any */
      $("#popupID").popup("open").enhanceWithin();
      /* close it */
      $("#popupID").popup("close");
      

    • 静态

    • Statically

      <a href="#popupID" data-rel="popup">Popup</a>
      

    • 这篇关于jQuery Mobile,更改页面时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 22:08