【问题标题】:JQuery Mobile loading style and scripts on refresh刷新时 JQuery Mobile 加载样式和脚本
【发布时间】:2013-05-07 00:06:51
【问题描述】:

JQM 加载页面的方式是通过 ajax 获取属性为 data-role="page" 的元素,而不是整个文档。

那么,如何让 JQuery Mobile 从任何页面(或刷新)加载样式和脚本,而不是仅在入口点 (index.htm) 中加载它们?

【问题讨论】:

    标签: javascript jquery jquery-mobile jquery-mobile-ajax


    【解决方案1】:

    只需将它们放入 BODY 标记中即可。

    在我的另一个回答中有描述:Why I have to put all the script to index.html in jquery mobile

    【讨论】:

      【解决方案2】:

      谢谢,我将所有的 JS 放在一个文件中,但 jquery、jqm 和 jqm css 文件也需要在每个页面上。我最终做的是在每个页面正文上包含一个脚本,以检查脚本是否存在。如果它们不存在,它们将被动态添加。

      应该是这样的

          if (document.getElementsByTagName('script') < 3)
          {
           createElement
           setAttribute
           append inside head element
           //repeat for each script / styleshet
          }
      
          else
           //do nothing 
      

      如果我采用将所有文件包含在正文中的方法,则每次页面更改时请求的资产都会出现冗余。我相信这可以解决。到目前为止它似乎有效。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-03-14
        • 2017-05-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-06-24
        相关资源
        最近更新 更多