【问题标题】:Uncaught TypeError: Cannot call method 'removeClass' of undefined未捕获的类型错误:无法调用未定义的方法“removeClass”
【发布时间】:2013-06-17 14:21:20
【问题描述】:

我动态创建了一个 jquery 移动复选框组。并想绑定事件以启用全选功能。执行后,chrome控制台提示“Uncaught TypeError: Cannot call method 'removeClass' of undefined”。这里是js代码:

var arr=['<fieldset id="countryContainer" name="countryContainer" data-role="controlgroup" data-type="horizontal">'];

arr.push('<input type="checkbox" id="country_all" name="country_all" value="all" /><label for="country_all">ALL</label>');      
for(var i=0;i<9;i++){
arr.push('<input type="checkbox" id="country_'+i+'" name="fe" value="'+i+'" /><label for="country_'+i+'">'+i+'</label>');       
}

arr.push('</fieldset>');

$('[name=cell1]').append(arr.join(''));

$.mobile.pageContainer.trigger("create");


var chkall=$('[name=country_all]');
chkall.on('change', function() {
var checked=(chkall.prop('checked')=="checked")? true:false;
$("#countryContainer").prop('checked',true).checkboxradio().checkboxradio("refresh"); //something goes wrong here.
});

还有html:






问题是我想通过选中 country_all 复选框来选中 countryContainer 中的所有复选框。有什么想法吗?

【问题讨论】:

  • 你在哪里打电话removeClass
  • 您上面的代码似乎没有 removeClass..
  • 请注意:您可以像 chkall.is(':checked') ? true : falsechkall[0].checked 一样检查已检查,如果您可能应该使用 prop() 而不是 attr() 进行检查。
  • @FelixKling 很可能是移动框架在更新小部件时。
  • @epascarello:啊,有道理。

标签: javascript jquery-mobile


【解决方案1】:

问题解决了。我在字段集上放错了 .checkboxradio('refresh') 。感谢@Omar。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-11-30
    • 2013-08-31
    • 2011-11-12
    • 2013-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多