2015-12-28 143 views
-2
<html> 

<head> 
</head> 
<script> 
    function ClickFun() { 
     document.getElementById("print").innerHTML = 100; 
    } 

    function ClickFunction() { 
     document.getElementById("print").innerHTML = 200; 
    } 

    function Click() { 
     document.getElementById("print").innerHTML = 150; 
    } 

    function hello() { 
     alert("you clicked the list"); 
    } 
</script> 

<body> 
    <select> 
     <option onclick="ClickFunction();">Chrome</option> 
     <option onclick="Click();">Mozilla</option> 
     <option onclick="ClickFun(); hello();">Eclipse</option> 
    </select> 
    <p id="print"></p> 
</body> 

</html> 
+1

的可能的复制[jQuery的选择选项单击处理(http://stackoverflow.com/questions/5749597/jquery-select-option-click-handler) –

+1

不要使用单击选择选项的事件,使用更改事件。 –

回答

0

正如Alexander所建议的那样,在select选项上使用onchange事件。

<html> 

<head> 
</head> 
<script> 
    function print(){ 
    switch(document.getElementById("browser").value){ 
     case "c": 
     document.getElementById("print").innerHTML = 100; 
     break; 
     case "m": 
     document.getElementById("print").innerHTML = 200; 
     break; 
     case "e": 
     document.getElementById("print").innerHTML = 150; 
     default: 
     alert("you clicked the list"); 
    } 
    }; 
</script> 

<body> 
    <select id="browser" onchange="print()"> 
     <option value="c">Chrome</option> 
     <option value="m">Mozilla</option> 
     <option value="e">Eclipse</option> 
    </select> 
    <p id="print"></p> 
</body> 

</html>