我有以下HTML:JQuery的.append忽略
<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,鼻翼:
<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>");
對於resons未知對我來說,結束標記沒有被注入頁面。
我試過上面的代碼,以及這樣的事情:
.append("<option value='Hide Labels'>Hide Label</option></select>")
有沒有解決「配料」這些元素某種需求爲單一.append?我想知道如果這種方法在加載到DOM中時看起來不是很好,所以它被忽略了...
謝謝!
你***不能***將不完整的元素附加到DOM。擺脫所有的追加,並在一次掃描行動。 –
是的,那是有效的。試圖變得太花哨。 –