Jquery show / hide仅适用于第一项

时间:2015-11-23 10:08:46

标签: jquery html hide show

HTML

                    <div class="form-group">
                        <div class="col-md-4 col-md-offset-4">
                            <label>Leave Type</label>
                            @Html.DropDownList("LeaveType", null, htmlAttributes: new { @class = "form-control" })
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-md-4 col-md-offset-4">
                            <br />
                            <label>Start Date</label>
                            @Html.TextBox("datetime.now", String.Format("{0:d}", "Start date"), new { id="startDate", @class = "datepicker", type = "text" })
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-md-4 col-md-offset-4">
                            <br />
                            <label>End Date</label>
                            @Html.TextBox("01-01-2015", String.Format("{0:d}", "End date"), new { id = "endDate", @class = "datepicker", type = "text" })
                        </div>
                    </div>

JQuery的

$('#LeaveType').change(function () {
            var value = $(this).val();
            if (value == "1") {
                $('#endDate').show();
                $('#startDate').show();
            }
            else {
                $('#startDate').hide();
                $('#endDate').hude();
            }
        })

当用户从“离开类型”下拉列表中选择特定值时,我想隐藏某些项目。但它只为第一个价值而努力。我也想隐藏标签,所以我尝试将id放在div class中,但它并没有这样做。我也尝试使用name,跟随其他人对SOF的解决方案,但我也没有运气。请帮忙!

0 个答案:

没有答案
相关问题