为什么在这里看不到optgroup?
显示所有选项,但不显示组名
http://jsfiddle.net/UCNJ8/
$('<select></select>').appendTo('body').append('<option value="0">test</option>')
.append($('<optgroup>group</optgroup>')
.append('<option value="1">group test</option>'));
最佳答案
组名是通过label
属性(HTML4 specification)设置的,而不是通过其内容设置的(只有option
元素可以是optgroup
元素的子级)。
$('<optgroup />', {label: "group"})
DEMO
关于jquery - optgroup不可见?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7138995/