我收到此错误并且我不明白错误: TypeError:this.label未定义
我尝试动态添加复选框(ajax)及其样式,但如果我调用refresh方法,则会出现此错误。
来自Ajax调用的成功:
var foo = '<div data-role="fieldcontain">'
+'<fieldset data-role="controlgroup">'
+' <legend>Choose as many snacks as youd like:</legend>'
+' <input type="checkbox" name="checkbox-1a" id="checkbox-1a" class="custom" />'
+' <label for="checkbox-1a">Cheetos</label>'
+' <input type="checkbox" name="checkbox-2a" id="checkbox-2a" class="custom" />'
+' <label for="checkbox-2a">Doritos</label>'
+' <input type="checkbox" name="checkbox-3a" id="checkbox-3a" class="custom" />'
+' <label for="checkbox-3a">Fritos</label>'
+' <input type="checkbox" name="checkbox-4a" id="checkbox-4a" class="custom" />'
+' <label for="checkbox-4a">Sun Chips</label>'
+'</fieldset>'
+'</div>';
$("#panel-wo-item").html(foo);
$("#panel-wo-item").checkboxradio().checkboxradio("refresh");
和html:
<div id="panel-wo-item">
<!-- checkboxes -->
</div>
如果我删除.checkboxradio(&#34; refresh&#34;);它有效,但看起来没有风格&#34;而且丑陋。
答案 0 :(得分:2)
checkboxradio窗口小部件应该应用于单个<input>
元素。您正在将它应用于容器,这可能是您遇到问题的原因。
您也不必明确地实例化这些小部件,jQuery Mobile可以通过a single method call为您实现这些小部件:
$("#panel-wo-item").html(foo).enhanceWithin();