<html>
<body>
<h1>演示如何访问 OPTGROUP 元素</h1>
<select size="4">
<optgroup id="myOptgroup" label="Chinese cars">
<option value="byd">BYD</option>
<option value="geely">GEELY</option>
<option value="gwm">GWM</option>
</optgroup>
</select>
<p>单击按钮可获取选项组的标签/说明。</p>
<button onclick="myFunction()">试一试</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myOptgroup").label;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>