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
oSelect.appendChild(oGroup);
// add an option after the group
oSelect.options[oSelect.options.length]= new Option('My new option','some value');
}
</script>

<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>
</select>
<input type="button" onclick="changeSelect()" value="Add an option group">
</form>

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">

<optgroup/>

即可!! 共參考. 

 


arrow
arrow
    全站熱搜

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