jQuery Mobile:未捕获无法在初始化之前调用 checkboxradio 上的方法;试图调用方法“刷新" [英] jQuery Mobile: Uncaught cannot call methods on checkboxradio prior to initialization; attempted to call method 'refresh'

查看:23
本文介绍了jQuery Mobile:未捕获无法在初始化之前调用 checkboxradio 上的方法;试图调用方法“刷新"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理这个问题.这些是我使用并导致上述问题的代码.

I am pulling my hair out dealing with this problem. These are the code that I used and caused the mentioned problem.

$(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 出现(作为一个对话框)并显示每个选中的复选框.

The above code is in a file named hod.php. The file contain a number of checkboxes. These checkboxes and be checked simultaneously and when I pressed the #at-site-btn button the at-site.php appear (as a dialog) and display every checked checkboxes.

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

This is where the problem occurred. When I pressed the back button in the dialog to go back to the previous page and tried to uncheck those checkboxes, the error pops out as mentioned in the title. There are no calls to 'refresh method' in my code so I don't see the way to fix this.

  1. 谁能提出解决这个问题的方法?
  2. 我用对了吗?(我对 jQuery Mobile 非常陌生.如果使用 JQM 背后有一些概念,请向我解释[我已经尝试阅读 JQM 文档,但对我来说似乎很不清楚]).

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

Best regards and thank you very much for your answers.

推荐答案

您使用的是哪个版本的 jQueryMobile?您可能需要使用 pageinit 而不是 pagecreate.jQueryMobile 文档的这一部分讨论了选择.

What version of jQueryMobile are you using? You might need to use pageinit instead of pagecreate. This portion of the jQueryMobile documentation talks about the choices.

对于重新绘制或创建,@Taifun 指出的解决方案,如下所示:

For re-painting or creation, the solution that @Taifun pointed out, which looks like:

$("input[type='radio']").checkboxradio();
$("input[type='radio']").checkboxradio("refresh");

对我来说效果很好,但它没有 100% 正确地绘制控件.单选按钮的边缘没有涂上圆角.

worked okay for me, but it didn't paint the controls 100% correctly. Radio buttons didn't get the edges painted with rounded corners.

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

Before I saw your code, I read here that you can call .trigger('create') on the container object and it worked for me. You are doing that but inside pagecreate instead of in pageinit.

这篇关于jQuery Mobile:未捕获无法在初始化之前调用 checkboxradio 上的方法;试图调用方法“刷新"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆