【问题标题】:jQuery Mobile - How to Check if the Browser supports jQuery Mobile eventsjQuery Mobile - 如何检查浏览器是否支持 jQuery Mobile 事件
【发布时间】:2011-01-28 21:36:46
【问题描述】:

我目前正在使用 jQuery Mobile“pagebeforecreate”页面初始化事件将内容加载到我的 html 页面中。此处讨论 jQuery Mobile 事件:http://jquerymobile.com/demos/1.0a2/#docs/api/events.html。在内容同步加载并附加到正文后,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 文件并显示链接。

【问题讨论】:

    标签: jquery events mobile


    【解决方案1】:

    http://jquerymobile.com/gbs/

    jQuery Mobile 正在努力支持 所有A级浏览器。这意味着 我们将积极测试 这些浏览器并确保它们 尽其所能。这 浏览器将收到完整的 jQuery 移动 CSS 和 JavaScript(虽然 最终的布局可能是 优雅降级的版本 全功能,取决于 浏览器)。

    要检查浏览器是否被定义为 A 级,您可以调用

    $.mobile.gradeA()
    

    我没有 IE 来检查它提供了什么,但你可以试一试

    【讨论】:

    • 谢谢!这很好用。我已经测试了“if (!$.mobile.gradeA())”,它在 IE 8 中有效。是否有关于“$.mobile.gradeA()”事件的文档?我在 jQuery Mobile 网站上没有看到任何关于它的信息。
    • 我应该通过提供返回此页面的链接来标记您
    猜你喜欢
    • 1970-01-01
    • 2011-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-08
    • 2023-03-20
    • 1970-01-01
    • 2020-01-04
    相关资源
    最近更新 更多