Pak*_*pus 2 css checkbox json jquery-mobile
我正在尝试刷新在菜单标签页脚中单击时在fieldset标记中附加的复选框的数量.第一个标签访问是可以的,但之后,所有复选框都不能再被检查.我已多次修改我的代码,但它不起作用.有时可以检查它们但不应用样式.有时它们无法检查但应用了样式.
我尝试过.controlgroup('refresh');,.checkboxradio("refresh");但没有一个正在工作.我看过大多数类似的问题,但他们没有帮我解决这个问题.可能是我把代码放在了错误的地方?
对于.checkboxradio("refresh");控制台始终记录此错误.在初始化之前无法调用checkboxradio上的方法; 试图调用方法'refresh'
这是我原来的HTML和JS
<div data-role="content" data-theme="a">
<div id='delete_wrapper'>
<a href="#" data-role="button" id='deleteButton'>Delete</a>
<a href="#" data-role="button" id='deleteAllButton'>Delete All</a>
</div>
<fieldset data-role="controlgroup" id='checkboxes_wrapper2'>
</fieldset>
</div>
Run Code Online (Sandbox Code Playgroud)
这是我的JS
runfirstDelete = true;
$('.delete_tab').click(function(){
$("#checkboxes_wrapper2").children().remove();
var dataIndex;
var dataName;
for(var i in localStorage)
{
dataIndex = JSON.parse(localStorage[i]).index;
dataName = JSON.parse(localStorage[i]).name;
if(runfirstDelete){ // This for 1st time visit, It's working okay.
$("#checkboxes_wrapper2").append('<input type="checkbox" name="'+dataIndex+'" id="checkbox'+dataIndex+'" value="'+dataIndex+'"/><label for="checkbox'+dataIndex+'">'+dataName+'</label>');
}
else{ //if not, trying to insert embedded style in element
$('#checkboxes_wrapper2').append('<div class="ui-checkbox"><input type="checkbox" value="'+dataIndex+'" name="'+dataIndex+'" id="checkbox'+dataIndex+'"><label for="checkbox'+dataIndex+'" data-corners="true" data-shadow="false" data-iconshadow="true" data-wrapperels="span" data-icon="checkbox-off" data-theme="a" data-mini="false" class="ui-checkbox-off ui-btn ui-btn-up-a ui-btn-corner-all ui-fullsize ui-btn-icon-left ui-btn-up-a"><span class="ui-btn-inner"><span class="ui-btn-text">'+dataName+'</span><span class="ui-icon ui-icon-checkbox-off ui-icon-shadow"> </span></span></label></div>');
}
}
runfirstDelete = false; //Then indicate that it's not 1st click on tab
});
Run Code Online (Sandbox Code Playgroud)
由于您要添加新元素,因此不会有jQuery Mobile小部件来增强它们,因此尝试调用它们的refresh()方法确实会失败.
告诉jQuery Mobile"赶上"新标记的一种简单方法是create在容器元素上触发事件:
$("#checkboxes_wrapper2").trigger("create");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2830 次 |
| 最近记录: |