技术开发 频道

jQuery Mobile开发进阶:API扩展介绍

  页面初始化

  jQuery Mobile提供了一个叫autoInitializePage的属性,这个属性表示页面是否应该初始化,其默认值为true。然而,如果是继承扩展了$.mobile对象,开发者则可以将该值设置为false,并且在稍晚的时候对页面初始化进行设置。下面的代码中,演示了当其他脚本在运行时,如何暂时延迟页面的初始化。如果有大量的客户端脚本运行,则一个很好的建议方法是延迟页面的初始化,直到DOM完成加载客户端脚本。

<!DOCTYPE HTML>
<html>
<head>
  
<title>Understanding the jQuery Mobile API</title>
  
<script type="text/javascript" src="jquery.js"></script>
  
<script type="text/javascript">
    $(document).bind(
"mobileinit", function() {
      $.mobile.autoInitializePage
= false;
    });
  
</script>
  
<script type="text/javascript" src="jquery.mobile.js"></script>
</head>        
<body>
  
<div data-role="page">
    
<div data-role="content">
      
<ul data-role="listview" id="my-list"></ul>
    
</div>
  
</div>
  
<script type="text/javascript">
    $(
'#my-list').html('<li><a href="page-2.html">Link to another page</a></li>');
    $.mobile.autoInitializePage = true;
  
</script>
</body>
</html>

 

  

  

  

  

  

  

  

  

  

  

 

  

 

  

 

  

 

  

 

  

  

  

0
相关文章