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

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

问题描述

我正在解决这个问题. 这些是我使用并引起上述问题的代码.

$(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文档,对我来说似乎不太清楚]).

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

解决方案

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

对于重新绘画或创建,@ Taifun 指出的解决方案,看起来像: 对我来说还可以,但它不能正确地绘制控件的100%.单选按钮的边缘未涂圆角.

在看到您的代码之前,我在此处阅读,您可以在容器对象上调用.trigger('create'),并且它可以正常工作为了我.您正在执行此操作,但是在pagecreate内部而不是在pageinit内部.

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');

    });
});

Explanation:

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. Can anyone please suggest a way to solve this problem?
  2. Am I using it right? (I am very new to jQuery Mobile. If there are some concepts behind using JQM please explain it to me [I've tried read JQM Docs it seems so unclear to me]).

Best regards and thank you very much for your answers.

解决方案

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.

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

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

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

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天全站免登陆