没有触发 onchange 事件,请看下面的示例,在下拉框中选择时触发,但点按钮,用程序选择,就不触发。<html>
<body>
<script>
function f1()
{
alert('changed');
}
function f2()
{
if(Sel1.selectedIndex==1)Sel1.selectedIndex=0;
else Sel1.selectedIndex=1;
}
</script>
<select id=Sel1 onchange='f1()'>
<Option value='a1'>aaa</Option>
<Option selected value='b1'>bbb</Option>
</Select>
<input type=button onclick='f2()' value='test'>
</body>
</html>
<body>
<script>
function f1()
{
alert('changed');
}
function f2()
{
if(Sel1.selectedIndex==1)Sel1.selectedIndex=0;
else Sel1.selectedIndex=1;
}
</script>
<select id=Sel1 onchange='f1()'>
<Option value='a1'>aaa</Option>
<Option selected value='b1'>bbb</Option>
</Select>
<input type=button onclick='f2()' value='test'>
</body>
</html>
<html>
<body>
<script>
function f1()
{
alert('changed');
}
function f2()
{
var oOption = document.createElement("OPTION");
Sel1.options.add(oOption);
oOption.innerText = "Two";
oOption.value = "2";
// if(Sel1.selectedIndex==1)Sel1.selectedIndex=0;
// else Sel1.selectedIndex=1;
}
</script>
<select id=Sel1 onchange='f1()'>
<Option value='a1'>aaa</Option>
<Option selected value='b1'>bbb</Option>
</Select>
<input type=button onclick='f2()' value='test'>
</body>
</html>
{
switch(event.propertyName)
{
default:
alert(event.propertyName);
}
}
<html>
<body>
<script>
function f1()
{
alert('changed');
}
function f2()
{
var oOption = document.createElement("OPTION");
Sel1.options.add(oOption);
oOption.innerText = "Two";
oOption.value = "2";
// if(Sel1.selectedIndex==1)Sel1.selectedIndex=0;
// else Sel1.selectedIndex=1;
}
</script>
<select id=Sel1 onpropertychange='f1()'>
<Option value='a1'>aaa</Option>
<Option selected value='b1'>bbb</Option>
</Select>
<input type=button onclick='f2()' value='test'>
</body>
</html>