2012-09-13 110 views

回答

0

你必須在你的代碼的一些錯誤。

你應該嘗試fllowing:

<!DOCTYPE html> 
<html>  
    <head>  
     <title>Sample Page</title>   
     <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" />  
     <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>   
     <script type="text/javascript" src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script> 
     <script type="text/javascript"> 

     $(document).ready(function() { 
      var jResult = [{"status":"ok", 
       "count":6, 
       "categories":[{ 
        "id":19, 
        "slug":"abcd", 
        "title":"abcd", 
        "post_count":1 
       }, 
       { 
        "id":6, 
        "slug":"conferences", 
        "title":"Conf\u00e9rences", 
        "post_count":33 
       }] // <--- You had a missing ']' 
      }]; 

      var buttonHtmlString = "", pageHtmlString = ""; 

      for (i = 0; i < 2; i++) { 
       // 'jResult' is an array so you should have 'jResult[0].categories[i].title' 
       // instead of 'jResult.categories[i].title' 
       buttonHtmlString += '<a href="#' + jResult[0].categories[i].title + '" data-role="button">' + jResult[0].categories[i].title + '</a>'; 
       pageHtmlString += '<div data-role="page" id="' + jResult[0].categories[i].title + '">'; 
       pageHtmlString += '<div data-role="header"><h1>' + jResult[0].categories[i].title + '</h1></div>'; 
       pageHtmlString += '<div data-role="content"><p>' + jResult[0].categories[i].post_count + '</p></div>'; 
       pageHtmlString += '</div>'; 
      } 

      $("#buttonGroup").append(buttonHtmlString); 
      $("#buttonGroup a").button(); 
      $("#buttonGroup").controlgroup(); 

      $("#main").after(pageHtmlString); 

      //return false; 
     }); 

     </script> 
    </head>  
    <body>    
     <div data-role="page" id="main">  
      <div data-role="header">   
       <h1> 
        Page 1 
       </h1>  
      </div><!-- /header -->  

      <div data-role="content"> 
       <p>I fake loaded content in the <i>$(document).ready()</i> event!</p> 
       <div data-role="controlgroup" id="buttonGroup"></div> 
      </div><!-- /content -->  

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

    </body> 
</html> 

希望這有助於。