我的控制组(jquery mobile 1.4)在最初动态创建无线电组时呈现完美,但是当我向其添加另一个无线电时,按钮被设置样式,但是分开。当我重新加载应用程序时,它们又在一起了。
function showPlaces() {
$('#radio-group').empty();
for(var i = 0; i < connections.length; i++) {
$('#radio-group').append('<label><input type="radio" name="places" id="' + i + '" />' + place + '</label>');
}
$('input[type=radio]').checkboxradio().trigger('create');
$('#radio-group').controlgroup().trigger('create');
}
//在应用程序启动时调用该函数,在添加其他位置后再次调用该函数
我尝试过的其他一些事情:
$("#radio-group").controlgroup("refresh");
$('#radio-group').controlgroup('refresh');
$("[data-role=controlgroup]").controlgroup("refresh");
$('input[type=radio]').checkboxradio('refresh');
在.append之前也试过.controlgroup('container'),但得到“在初始化之前无法在控制组上调用方法”。
这是html:
<form>
<fieldset data-role="controlgroup" id="radio-group">
<!-- Dynamically injected radio buttons go here -->
</fieldset>
</form>
答案 0 :(得分:4)
您应该将.append()
个项目放入 for {/ em>中的.controlgroup("container")
,然后增强单选按钮.checkboxradio()
。
for(var i = 0; i < connections.length; i++) {
$('#radio-group')
.controlgroup("container")
.append('<label><input type="radio" name="places" id="+i+" />Place</label>');
}
$("#radio-group")
.enhanceWithin()
.controlgroup("refresh");
您甚至不需要使用.checkboxradio()
,而是在父容器上使用.enhanceWithin()
。
<强> Demo