1

我是 AJAX 和 PHP 的新手,我有以下代码:

<head>
    <script type="text/javascript">
        function crimeselect(){
            var select = document.getElementById("crime").value;
        }
    </script>
</head>
<body>
    <select name="crime" id="crime" onChange="crimeselect();">
        <option value="CVPerson">Crimes VS Person</option>
        <option value="CVMO">Crimes VS Moral and Order</option>
        </select>

    <select id="CVPerson" onchange="">
        <option>Homicide</option>
        <option>Kidnapping</option>
    </select>

    <select id="CVMO" onchange="">
        <option>Alarm and Scandal</option>
        <option>Assault/Resistance to Authority</option>
    </select>
</body>

我想要的是,当我选择“Crimes VS Person”时,ID 为“CVPerson”的选择选项只会出现,而 ID 为“CVHO”的选择选项不会出现。如果我选择“犯罪 VS 道德和秩序”也一样。

我不知道该怎么做。请有任何提示。

4

1 回答 1

0
<head>
    <script type="text/javascript">
        function crimeselect(){

            document.getElementById(document.getElementById("crime").value).style.visibility = 'visible';         

        }
    </script>
</head>
<body>
    <select name="crime" id="crime" onChange="crimeselect();">
        <option value="CVPerson">Crimes VS Person</option>
        <option value="CVMO">Crimes VS Moral and Order</option>
        </select>

    <select id="CVPerson" onchange="" style="visibility:hidden;">
        <option>Homicide</option>
        <option>Kidnapping</option>
    </select>

    <select id="CVMO" onchange=""  style="visibility:hidden;">
        <option>Alarm and Scandal</option>
        <option>Assault/Resistance to Authority</option>
    </select>
</body>​​​
于 2012-11-15T15:15:07.970 回答