jquery mobile,仅使用控件?

时间:2011-01-25 21:05:47

标签: jquery-mobile

我对使用jquery移动控件很感兴趣,但只有使用它才能使用“page”标签。

使用页面进行大量自动注入到html加链接等通过ajax进行后退按钮。我对各种自动ui都不感兴趣。

如何在不制作整页jquery移动页面的情况下使用jquery移动控件(按钮,链接,列表等)?

3 个答案:

答案 0 :(得分:3)

来自the jQuery Mobile Alpha 2 release notes

  

全局配置

     

jQuery Mobile现在有许多方法来override the initial configuration框架的许多方面(例如禁用的Ajax样式链接或表单)。这可以让你雕刻jQuery Mobile在更专业的情况下工作,并且不适合框架的完整设计方法(例如,你可以只使用几个小部件而不是整个框架)


因此,您可以通过禁用您不想要的位来使用jQuery Mobile àlacarte 。例如,要禁用ajaxical导航和表单:

$(document).live("mobileinit", function() {
    $.mobile.ajaxLinksEnabled = false;
    $.mobile.ajaxFormsEnabled = false;
});

NB ,正如链接的文档页面所说,您需要在加载jQuery Mobile之前执行自定义JavaScript(如上面的代码段),因此导入你的脚本是这样的:

<script src="jquery.js"></script>
<script src="custom-scripting.js"></script>
<script src="jquery-mobile.js"></script>

答案 1 :(得分:2)

我也想这样做。但是我想要为已经使用jQuery UI的页面添加控件,所以还有一些额外的步骤。

  1. 还必须禁用ajax处理以使我的常规(非jqm)按钮正常提交/正常工作

    $(document).live("mobileinit", function() {
        $.extend($.mobile, {
            autoInitializePage: false,
            linkBindingEnabled: false,
            ajaxEnabled: false
        });
    });
    
  2. JQM和jQuery UI都有一个名为“button”的小部件,所以一个覆盖另一个,所以我将JQM小部件名称更改为mbutton以停止碰撞

    $.widget("mobile.mbutton", $.mobile.widget, {
    
  3. 在JQM的初始化代码中,在渲染期间停止隐藏内容,因为我们设置了autoInitializePage = false,因此我们希望避免显示页面的5秒超时

    if ($.mobile.autoInitializePage) {
        // Add mobile, initial load "rendering" classes to docEl
        $html.addClass("ui-mobile ui-mobile-rendering");
        // This is a fallback. If anything goes wrong (JS errors, etc), or events don't fire,
        // this ensures the rendering class is removed after 5 seconds, so content is visible and accessible
        setTimeout(hideRenderingClass, 5000);
    }
    
  4. JQM和JQUI都有碰撞的ui-icon css,所以我在两个地方的JQM css中添加了一个额外的'.ui-mobile'选择器:

    /* Icons
    ----------------------------------------------------*/
    .ui-mobile .ui-icon,
    .ui-mobile .ui-icon-searchfield:after {
    
    ...
    
    /* Alt icon color
    ----------------------------------------------------*/
    .ui-mobile .ui-icon-alt {
    
  5. 只需初始化控件,就像使用任何jQuery UI控件一样:

    $(".my-slider").slider();
    
  6. 免责声明:到目前为止,我只使用了滑块作为切换开关,因此可能会有更多的css和js进行修补,我需要做一些自定义的CSS调整来将滑块重新定位在其轨道中。 / p> HTH其他任何人都希望这样做。

答案 2 :(得分:0)

Jquery Mobile添加了一个构建器,您可以在其中挑选并准确选择要包含的部分:

http://jquerymobile.com/download-builder/