显示第二次下拉基于第一次下拉不工作

时间:2015-03-12 15:38:26

标签: javascript jquery html5 drop-down-menu

我是一名新手学习网站开发。我试图用两个下拉菜单创建一个简单的表单。基于第一次下拉第二次下降应该是可见的。

但它不起作用:

 <!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>

 <div class="container">
    <div class="box">
    <form>
  <div class="ccms_form_element cfdiv_custom">

                <div class="col-md-4">
                    <label for="inputType">Input Type</label></div>
                <div class="col-md-8" style="font-size:16pt;">
                    <select id="inputType" required name="inputType" style="width:500px" onChange="ChangeDropdowns();">
                        <option value="">Select Type : Type Of You Want to Process</option>
                        <option value="text">Text  </option>
                        <option value="genome">Numbers</option>
                        <option value="chacha">Special Characters</option>
                    </select>
                </div>
            </div>
  </div>

   <div class="style-sub-1" id="dataType" style="display: none;" >
                <div class="col-md-4">
                    <label for="inputType">Data Type</label></div>
                <div class="col-md-8" style="font-size:16pt;">
                    <select id="data" required name="data" style="width:500px">
                        <option value="">Select Data Source : Where is your Data?</option>
                        <option value="text">Data is already in Server</option>
                        <option value="genome">Need to Upload the File</option>

                    </select>
                </div>
                  </div>

                    <div class="row">



<script>

function ChangeDropdowns() {  

$(".style-sub-1").show();
}

</script>
</body>

</html>

有人可以告诉我这里做错了吗?

2 个答案:

答案 0 :(得分:0)

使用以下内容,使用JQuery检测第一个选择中的更改 - 并包括JQuery,如Scott所说

$( document ).ready(function() {
  $("#inputType").on('change', function (){
    $(".style-sub-1").show();
  });
});

答案 1 :(得分:0)

看起来你正在尝试使用jquery(你的javascript代码中的$)。 但是,您还没有在html中指定jquery脚本。

尝试添加此

<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.3.js"></script>

在头块之间