2011-01-28 102 views
0

我目前使用jQuery Mobile「pagebeforecreate」頁面初始化事件將內容加載到我的html頁面。這裏討論jQuery Mobile事件:http://jquerymobile.com/demos/1.0a2/#docs/api/events.html。內容同步加載後附加到主體jQuery Mobile格式化頁面。jQuery Mobile - 如何檢查瀏覽器是否支持jQuery Mobile事件

這裏是我的代碼在瀏覽器上運行,支持jQuery Mobile的:

<!DOCTYPE html> 
<html> 
<head> 
    <title>jQuery Mobile Test</title> 
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a2/jquery.mobile-1.0a2.min.css" /> 
    <script src="http://code.jquery.com/jquery-1.4.4.min.js"></script> 

    <script> 
    $('body').live('pagebeforecreate',function(event){ 

     var ajaxContent = ""; 

     $.ajax({ 
      async: false, 
      type: "GET", 
      url: "test.xml", 
      dataType: "xml", 
      success: function(xml) { 

       $(xml).find('item').each(function() 
       { 
        ajaxContent += '<li><a href="'+$(this).find('link').text()+'">'+$(this).find('title').text()+'</a></li>'; 
       }); 
       //alert(ajaxContent); 
       $('#menu').append(ajaxContent); 
      } 
     }); 
    }); 
    </script> 

    <script src="http://code.jquery.com/mobile/1.0a2/jquery.mobile-1.0a2.min.js"></script> 
</head> 
<body> 
<noscript>You must have JavaScript enabled to view the content on this website.</noscript> 
<div data-role="page"> 

    <div data-role="header"> 
     <h1>jQuery Mobile</h1> 
    </div> 

    <div data-role="content"> 

     <ul data-role="listview" id="menu"> 

      <li><a href="#">Static</a></li> 

     </ul> 

    </div> 
</div> 
</body> 
</html> 

,這裏是XML文件:

<?xml version="1.0" encoding="UTF-8"?> 
<menu> 
<item> 
<title>Awesome Link from XML 1</title> 
<link>http://www.google.com</link> 
</item> 
<item> 
<title>Awesome Link from XML 2</title> 
<link>http://www.gmail.com</link> 
</item> 
</menu> 

我如何可以檢測瀏覽器是否支持「pagebeforecreate」 jQuery Mobile事件?或者有沒有辦法檢測這個事件是否被執行?如果這個事件從未執行,我需要用另一個函數加載XML。即使IE 8不支持jQuery Mobile,我仍然喜歡它來處理XML文件並顯示鏈接。

回答

3

http://jquerymobile.com/gbs/

jQuery Mobile的工作,支持 所有A級瀏覽器。這意味着我們將主動測試 這些瀏覽器,並確保他們的 盡其所能。該 瀏覽器將收到完整的jQuery 移動CSS和JavaScript(雖然 最終的佈局可能的 全功能的 優雅降級版本,這取決於 瀏覽器)。

要檢查瀏覽器被定義爲A級,你可以叫

$.mobile.gradeA() 

我沒有IE檢查什麼,讓這一點,但你可以給它一個嘗試

+1

謝謝!這很好。我測試了「if(!$。mobile.gradeA())」,它在IE 8中工作。「$ .mobile.gradeA()」事件中是否有任何文檔?我在jQuery Mobile網站上沒有看到任何關於它的信息。 – Greg 2011-01-31 06:00:14

相關問題