-1

当用户从我的列表框中选择一个选项时,我需要知道如何执行脚本。我当前的代码(尽管这可能是错误的方法是:

<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>
4

1 回答 1

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'); };
于 2013-10-15T01:32:21.310 回答