Chrome refuses to show a dynamically created OPTGROUP label in the following code. Works okay in IE6/7, Opera9, FF2/3. I'm sure this approach is DOM compliant. Copy & paste into an empty html file...

<script language="javascript">
function changeSelect(){
// create new option group
var oGroup = document.createElement('OPTGROUP');
oGroup.label = "My Label";
// get a reference to the `select' element
var oSelect = document.getElementById('select1');
// append the option group
// add an option after the group
oSelect.options[oSelect.options.length]= new Option('My new option','some value');

<form name="form1" id="form1">
<select name="select1" id="select1">
<option value='a0'>a0</option>
<option value='a1'>a1</option>
<option value='a2'>a2</option>
<option value='a3'>a3</option>
<option value='a4'>a4</option>
<input type="button" onclick="changeSelect()" value="Add an option group">

I tried to search for a technical developers group to discuss this but kept finding my way back to this Help group. So I guess this is the only place to ask? Thanks.

Solution :


<optgroup label="測試1"><optgroup/>


<optgroup label="測試1">


即可!! 共參考. 




Frank 發表在 痞客邦 PIXNET 留言(0) 人氣()