【问题标题】:jQuery Mobile: Uncaught cannot call methods on checkboxradio prior to initialization; attempted to call method 'refresh'jQuery Mobile:未捕获的无法在初始化之前调用 checkboxradio 上的方法;试图调用方法“刷新”
【发布时间】:2012-10-02 14:01:44
【问题描述】:

我正在努力解决这个问题。 这些是我使用并导致上述问题的代码。

$(document).ready(function () {
    $("#at-site-btn").bind("tap", function () {
        $.mobile.changePage("view/dialog/at-site.php", { transition:"slidedown", role:"dialog" });
    });
    $('#at-site-page').live('pagecreate', function(){
        var $checked_emp    = $("input[type=checkbox]:checked");
        var $this           = $(this);
        var $msg            = $this.find("#at-site-msg");
        $checked_emp.appendTo($msg);
        $checked_emp.trigger('create');
        $msg.trigger('create');
        $(document).trigger('create');
        $this.trigger('create');
        $("html").trigger('create');

    });
});

解释:

以上代码位于名为 hod.php 的文件中。该文件包含许多复选框。这些复选框同时被选中,当我按下#at-site-btn 按钮时,at-site.php 会出现(作为对话框)并显示每个选中的复选框。

这就是问题发生的地方。当我按下对话框中的后退按钮返回上一页并尝试取消选中这些复选框时,会弹出标题中提到的错误。我的代码中没有调用“刷新方法”,所以我看不到解决此问题的方法。

  1. 谁能提出解决此问题的方法?
  2. 我用对了吗? (我对 jQuery Mobile 非常陌生。如果在使用 JQM 背后有一些概念,请向我解释一下[我已经尝试阅读 JQM Docs,我觉得它似乎很不清楚])。

最好的问候,非常感谢您的回答。

【问题讨论】:

  • 或许this solution也能帮到你……
  • @Taifun - 感谢您为我指出解决方案

标签: jquery-mobile refresh uncaught-exception


【解决方案1】:

您使用的是哪个版本的 jQueryMobile?您可能需要使用pageinit 而不是pagecreatejQueryMobile documentation 的这一部分讨论了选择。

对于重绘或创作,solution that @Taifun 指出,它看起来像:

$("input[type='radio']").checkboxradio();
$("input[type='radio']").checkboxradio("refresh");
对我来说没问题,但它没有 100% 正确地绘制控件。单选按钮的边缘没有画成圆角。

在看到您的代码之前,我 read here 表示您可以在容器对象上调用 .trigger('create'),它对我有用。您正在这样做,但在 pagecreate 中而不是在 pageinit 中。

【讨论】:

    【解决方案2】:

    我实际上使用的是flipswitch checkbox

    <div class="some-checkbox-area">
        <input type="checkbox" data-role="flipswitch" name="flip-checkbox-lesson-complete"
               data-on-text="Complete" data-off-text="Incomplete" data-wrapper-class="custom-size-flipswitch">
    </div>
    

    所以had to do this:

    $("div.ui-page-active div.some-checkbox-area div.ui-flipswitch input[type=checkbox]").attr("checked", true).flipswitch( "refresh" ) 
    

    查看我的完整答案here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-13
      相关资源
      最近更新 更多