我已经看到了这个问题的变体,但我在SO上没有看到我的具体情况,所以这里就是这样。
我在使用jQuery移动将新的无线输入动态添加到现有控制组时遇到问题。它将添加,但是样式不正确,并且它似乎没有与其他输入正确交互。
这是我的小提琴:http://jsfiddle.net/cjindustries/3mQF6/
有没有人看到我做错了什么?或者是重新生成整个字段集的/controlgroup?:(
谢谢!下面的代码也是...
<div id="testPage" data-role="page">
<div data-role="content">
<fieldset data-role="controlgroup">
<legend>Radio buttons, vertical controlgroup:</legend>
<input type="radio" name="radio-choice-1" id="radio-choice-1" value="choice-1" checked="checked">
<label for="radio-choice-1">Cat</label>
<input type="radio" name="radio-choice-1" id="radio-choice-2" value="choice-2">
<label for="radio-choice-2">Dog</label>
<input type="radio" name="radio-choice-1" id="radio-choice-3" value="choice-3">
<label for="radio-choice-3">Hamster</label>
<input type="radio" name="radio-choice-1" id="radio-choice-4" value="choice-4">
<label for="radio-choice-4">Lizard</label>
</fieldset>
</div>
</div>
$('<input type="radio" name="radio-choice-5" id="radio-choice-5"><label for="radio-choice-5">Horse</label>')
.appendTo("fieldset");
$("fieldset").trigger('create');发布于 2013-07-09 19:06:06
您需要使用上面使用过的name="radio-choice-1"。这解决了你的行为问题
使用下面的代码解决了行为问题,修改后的代码可以动态添加无线电。
$('<input type="radio" name="radio-choice-1" id="radio-choice-5"><label for="radio-choice-5">Horse</label>').appendTo("fieldset");以下更改解决了样式问题,只需重新创建div而不是fieldset
$("div").trigger('create');检查Fiddle Demo
https://stackoverflow.com/questions/17546586
复制相似问题