【问题标题】:jQuery Mobile Dynamic Content InsertionjQuery Mobile 动态内容插入
【发布时间】:2012-01-27 21:32:45
【问题描述】:

好的,有人能帮我弄清楚为什么下面代码中的“测试”li 不可见吗?我检查了 live dom,元素似乎正在被处理:

<!DOCTYPE HTML> 
<html> 
<head> 

  <!-- Grab Google CDN's jQuery, with a protocol relative URL; fall back to local if necessary -->
  <script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
  <script src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script>
  <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" />
  <script>
  $(document).ready(function(){
      $('<div data-role="content" class="content"><ul data-role="listview" data-inset="true"><li><a href="#im?at=animals">test</a></li></ul></div>').appendTo("#home").page();
      $.mobile.changePage("#home", {transition: "none"});
  });
  </script>
</head> 

<body> 
<div id="home" data-role="page"> 
</div> 
</body> 
</html>

提前致谢。

【问题讨论】:

    标签: jquery dynamic jquery-mobile pagefunction


    【解决方案1】:

    对 changePage 的调用不起作用,因为您只有一个默认情况下可见/活动的页面。 您可以通过触发 create 事件来强制更新活动页面。

    $('<div data-role="content" class="content"><ul data-role="listview" data-inset="true"><li><a href="#im?at=animals">test</a></li></ul></div>').appendTo("#home");
    $.mobile.changePage("#home", {transition: "none"});  
    $.mobile.activePage.trigger('create'); 
    

    【讨论】:

      【解决方案2】:

      下面的元素将display 属性设置为none,并且隐藏了它的兄弟元素:

      <div data-role="content" class="content ui-page ui-body-c ui-content" tabindex="0" role="main">
      

      CSS 规则:

      .ui-mobile [data-role="page"], .ui-mobile [data-role="dialog"], .ui-page {
      top: 0;
      left: 0;
      width: 100%;
      min-height: 100%;
      position: absolute;
      display: none;
      border: 0;
      }
      

      【讨论】:

      • 您知道触发它显示的正确 jquery 移动方法吗?我认为这就是 changePage 对 transition none 所做的事情。
      • 我刚刚检查了test 的祖先,看看为什么test 是不可见的,发现其中一个(至少)有display: none
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-11
      • 2013-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-01
      • 1970-01-01
      相关资源
      最近更新 更多