当用户从我的列表框中选择一个选项时,我需要知道如何执行脚本。我目前的代码(虽然这可能是错误的方法是:
<form>
Character Name: <input type="text" name="charname">
</form>
Server Region: <select id="serverloc">
<option value="4">US</option>
<option value="Oceanic">Oceanic</option>
</select>
<script>
var serverloc = document.getElementById(4);
if ( serverloc == "Oceanic" ) {
document.Write("it Worked!")
}
</script>
答案 0 :(得分:1)
Server Region: <select id="serverloc">
<option value="4">US</option>
<option value="Oceanic">Oceanic</option>
</select>
JS:
var select = document.getElementById('serverloc');
select.onchange = function(){ alert('yay'); };