onclick功能在chrome中不起作用

时间:2015-12-28 07:46:12

标签: javascript onclick

<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 个答案:

答案 0 :(得分:0)

正如亚历山大所建议的那样,在选择选项上使用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>