使用js 在IE和火狐firfox 里动态增加select 的option

使用js 在IE和火狐firfox 里动态增加select 的option

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
function SelectTypeChange()
{
    var ObjSelect = document.getElementById("SelectType");
    var ObjSelect2 = document.getElementById("SelectFlowerBianbian");
    var StrText = "朵鲜花";
    if( ObjSelect !=null && ObjSelect2 != null)
    {
        if(ObjSelect.options[ObjSelect.options.selectedIndex].value == 2)
        {
        StrText = "个炸弹";
        }
        ObjSelect2.options.length =0;
        for(var i=0; i<6; i++){
            var newOption11=new Option(i + StrText,i);
            ObjSelect2.options.add(newOption11);
            }
       
    }
   
}
//-->
</SCRIPT>
<BODY>
<select name="SelectType" id="SelectType"  onchange="SelectTypeChange();">
<option value="1">送鲜花</option><option value="2">送炸弹</option>
</select>

<select name="SelectFlowerBianbian" id="SelectFlowerBianbian"><option value="0">0朵鲜花</option><option value="1">1朵鲜花</option><option value="2">2朵鲜花</option><option value="3">3朵鲜花</option><option value="4">4朵鲜花</option><option value="5">5朵鲜花</option></select>
</BODY>
</HTML>

 

用下面地来增加option项目在火狐里是不行的

var oOption = document.createElement("OPTION");
document.getElementById("IdOfOpt").options.add(oOption);
oOption.Text = "顯示的文字"; // 或用 oOption.innerText = "..."
oOption.Value = "數值";

你可能感兴趣的:(select)