php - 使用 jQuery Mobile 动态创建虚拟页面

标签 php javascript jquery ajax jquery-mobile

我尝试使用 jQuery Mobile 链接虚拟页面,但我遇到了两个问题:

  • 第一次加载页面时,没有应用 CSS。
  • 当我选择一个页面并想切换到另一个页面时,我注意到每次经过该页面 1。

这是我的 example .

代码:

            var nbrButton = 3;
            $(document).ready(function(){
                for(i = 1;i <= nbrButton;i++) {

                    $("body").append('<div id="p'+i+'" data-role="page" class="pages"><div data-role="content">Page'+i+'</br><a data-role="button" rel="internal" href="#p1"  data-inline="true">1</a><a data-role="button" rel="internal" href="#p2"  data-inline="true">2</a><a data-role="button" rel="internal" href="#p3"  data-inline="true">3</a></div></div>');

                }
                $("#p1").show();

            });

你能告诉我问题是什么吗,或者是否有更好的方法。

谢谢。

最佳答案

更新

我还删除了链接中的 data-rel="internal"

回答

我已经完成了以下内容。

代替

$('#p1').show();

我加这个

$.mobile.changePage( '#p1', { allowSamePageTransition: true });

它将刷新第 1 页 p1 以重新加载样式。

工作 example .

关于php - 使用 jQuery Mobile 动态创建虚拟页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15550295/

相关文章:

php - 根据重复值合并数组php

php - 确定两个用户是否通过 friend 的 friend 建立联系

javascript - 具有灵事件态视觉样式功能的 JS 文本编辑器控件

javascript - 如何在音频时间更新上获取 clientx

jquery - 在 Galleria 照片库上设置标题

javascript - Knockout.js:推送项目 -> 指定新的 DOM 元素

Jquery选择: populate Multiple Select with Tab button

php - 从 URL 解析域

javascript - 页面重新加载后保持 onclick jquery

javascript - Angular 5 : I can navigate to a module's route without including the module's path segment in the URL?