当Dropdownbox选项改变时,asp.net mvc显示/隐藏div

时间:2016-12-02 19:05:09

标签: javascript html asp.net-mvc

我在.cshtml中有 Dropdownbox 列表,如下所示:

<div class="form-group">
    @Html.Label("Role", new { @class = "col-md-2 control-label" })
    <div class="col-md-10">
        @Html.DropDownList("Name", null, new { @class = "form-control" })
    </div>
</div>

这是我的第一个和第二个div

<div class="StudentSection" style="display:none;">
Some contents
</div> 

<div class="LecturerSection" style="display:none;">
Some contents
</div>

.js

中提供了我的代码
<script type="text/javascript">
$(document).ready(function () {
    $("#StudentSection").hide();
    $("#LecturerSection").hide();

    $("#Name").change(function () {
        if ($("#Name").val() == "Student") {
            $("#StudentSection").show();
            $("#LecturerSection").hide();
        }
        else {
            $("#LecturerSection").show();
            $("#StudentSection").hide();
        }
    });
});
</script>

这些代码对我不起作用。

1 个答案:

答案 0 :(得分:0)

"0"#StudentSection更改为#LecturerSection.StudentSection,因为它们似乎是 ID

在演示中看到这个

&#13;
&#13;
.LecturerSection
&#13;
&#13;
&#13;

相关问题