我有一个单选按钮,它具有显示或隐藏单选按钮状态的div内容辩护的选项,但是在我填写表格并按F5键后,先前的状态保持不变,但是div类消失了。
$(document).ready(function () {
$("input[name$='Chapel']").click(function () {
var test = $(this).val();
if (test == 'No') {
$("div#hideChapel").hide();
}
else {
$("div#hideChapel").show();
}
});
});
HTML
<div class="form-group">
@Html.LabelFor(model => model.Chapel, htmlAttributes: new { @class = "control-label col-md-3" })
<div class="col-md-9">
<label class="radio-inline">
@Html.RadioButtonFor(model => model.Chapel, "Yes", new { @class = "styled", htmlAttributes = new { @checked = "true", @name = "Chapel"} }) Yes
</label>
<label class="radio-inline">
@Html.RadioButtonFor(model => model.Chapel, "No", new { @class = "styled", htmlAttributes = new { @checked = "true" , @name = "Chapel" } })
No
</label>
@Html.ValidationMessageFor(model => model.Chapel, "", new { @class = "text-danger" })
</div>
</div>
任何评论,应该在哪里出现问题?
答案 0 :(得分:1)
刷新页面后,如果要显示div,则需要在点击功能之外添加该代码。
$(document).ready(function () {
// Add logic when to show this div
$("div#hideChapel").show(); // Here you go
$("input[name$='Chapel']").click(function () {
var test = $(this).val();
if (test == 'No') {
$("div#hideChapel").hide();
}
else {
$("div#hideChapel").show();
}
});
});