我正在解决这个问题。
这些是我使用并引起上述问题的代码。
$(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出现(作为对话框)并显示每个选中的复选框。
这是发生问题的地方。当我在对话框中按“后退”按钮返回上一页并尝试取消选中这些复选框时,错误弹出,如标题中所述。我的代码中没有对“刷新方法”的调用,因此我看不到解决此问题的方法。
最好的问候,非常感谢您的回答。
最佳答案
您正在使用哪个版本的jQueryMobile?您可能需要使用pageinit
而不是pagecreate
。 jQueryMobile documentation的这一部分讨论选择。
对于重新绘画或创建,solution that @Taifun指出,它类似于:
$("input[type='radio']").checkboxradio();
$("input[type='radio']").checkboxradio("refresh");
对我来说还可以,但它不能正确地绘制控件的100%。单选按钮的边缘未涂圆角。在我看到您的代码之前,我read here可以在容器对象上调用
.trigger('create')
,它对我有用。您正在执行此操作,但是在pagecreate
内部而不是pageinit
中。
关于jquery-mobile - jQuery Mobile : Uncaught cannot call methods on checkboxradio prior to initialization; attempted to call method 'refresh' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12691780/