我试图在选定的下拉列表项目发生更改时更改分区内显示的值。单击按钮执行此操作是我到目前为止所做的工作,但是,我想知道每次选择更改时是否可以自动更改此值。当下拉列表项目发生变化时,动态显示所选项目作为警报(Javascript)
<select id="mySelect">
<option value="st1" selected="selected">Create new Stream</option>
<option value="st1">Stream 1</option>
<option value="st2">Stream 2</option>
<option value="st3">Stream 3</option>
<option value="st4">Stream 4</option>
</select>
<input type="button" value="show attributes" class="panel-button-attr" onclick="choice()">
我的js函数:
function choice() {
var choice=document.getElementById("mySelect");
var strUser = choice.options[choice.selectedIndex].text;
if(strUser=="Stream 1"){
alert("You selected Stream 1");
}
else if(strUser=="Stream 2"){
alert("You selected Stream 2");
}
else if(strUser=="Stream 3"){
alert("You selected Stream 3");
}
else if(strUser=="Stream 4"){
alert("You selected Stream 4");
}
else {
alert("Create Stream");
}
}
根据这个代码,我需要在不调用选择(0函数每次显示警报消息相反,它应该在每一个选择更改警报。下拉列表
感谢这个作品 –