【发布时间】:2017-02-01 21:08:35
【问题描述】:
我正在尝试将选中的复选框状态动态设置为 false/true。 我到目前为止是这样的:
for(var i = 0; i < bookmakers.length; i++) {
$('#' + bookmakers[i].id + '-checkbox').prop('checked', filters['bookmakers'][bookmakers[i].id]).change();
console.log($('#' + bookmakers[i].id + '-checkbox'));
}
当我从控制台获取日志时,一些复选框被选中:true 和一些选中:false。问题是我在视觉上看到所有复选框都被选中。我们正在使用材料设计,这里是创建复选框的一些示例:
for(var i = 0; i < bookmakers.length; i++) {
$bookmakers.append('<label class="mdl-switch mdl-js-switch mdl-js-ripple-effect"><input id="' + bookmakers[i].id + '-checkbox" type="checkbox" class="mdl-switch__input" checked><span class="mdl-switch__label">' + bookmakers[i].name + '</span></label>');
}
然后我这样做:
if(typeof componentHandler != 'undefined')
componentHandler.upgradeDom();
更新视图。有什么想法吗?
【问题讨论】:
标签: javascript jquery checkbox material-design