我有以下 HTML:
<div id='show-label'>
<select id="comboboxShowLabel">
<option value="">Hide or show labels?</option>
<option value="Show Labels">Show Label</option>
<option value="Hide Labels">Hide Label</option>
</select>
</div>
我想添加<select></select>
运行时到父 div,ala:
<div id='show-label'>
</div>
$("#show-label").html("<select id='comboboxShowLabel'>")
.append("<option value=''>Hide or show labels?</option>")
.append("<option value='Show Labels'>Show Label</option>")
.append("<option value='Hide Labels'>Hide Label</option>")
.append("</select>");
对于我未知的原因,结束标签没有被注入到页面中。
我已经尝试过上面的代码以及类似的代码:
.append("<option value='Hide Labels'>Hide Label</option></select>")
将这些元素“批处理”到单个 .append 中是否存在某种排序要求?我想知道这种方法在加载到 DOM 时是否看起来格式不正确,因此被忽略了......
Thanks!
尝试这个:
$("#show-label").append(function() {
return $("<select id='comboboxShowLabel'>")
.append("<option value=''>Hide or show labels?</option>")
.append("<option value='Show Labels'>Show Label</option>")
.append("<option value='Hide Labels'>Hide Label</option>");
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)