更新时间:2022-12-14 22:46:14
根据w3schools ,选项标签确实支持onclick属性。我尝试使用IE6的底部,这似乎并非如此。
According to w3schools, the option tag does support an onclick attribute. I tried with with bottom of the barrel IE6 and this doesn't seem to be the case.
最简单的方法是:
<select multiple="multiple" onchange="alert(this.value);">
<option value="tx">Texas</option>
<option value="ak">Alaska</option>
<option value="ca">California</option>
<option value="ws">Washington</option>
<option value="tn">Tennessee</option>
</select>
这不是你想要的,但应该非常接近。
This is not exactly what you are after, but should be pretty close.
编辑
这只需要更多工作:
<select multiple="multiple" onchange="
switch (this.value){
case 'tx': funcOne(); break;
case 'ak': funcTwo(); break;
etc...
}
">
<option value="tx">Texas</option>
<option value="ak">Alaska</option>
<option value="ca">California</option>
<option value="ws">Washington</option>
<option value="tn">Tennessee</option>
</select>
此时将onchange包装成js文件中的函数而不是嵌入是合适的它在html中。
At this point it would be appropriate to wrap the onchange into a function in a js file instead of embedding it in the html.