我是编程的新手,自2月以来我基本上都在尝试自学。我已经设法使用Visual Studio / MVC5创建了一个基本的表单,但我正在努力解决一些更复杂的功能问题。
这里我有一个禁用的复选框(id = withdrawn),我希望它在启用'update'(id = update)复选框后启用。我还希望仅在勾选相同的“更新”复选框时才显示“RefNumber”文本框。任何帮助将不胜感激。
@model F10New.ViewModels.NewSubmissionForm
@{
ViewBag.Title = "NewSubmission";
Layout = "~/Views/Shared/_Layout.cshtml";
}
@using (Html.BeginForm("Save", "Notifications"))
{
<p>*Is this the initial notification of the project p>
<div class="form-inline">
<div class="checkbox" id="initialNotification">
<label>
@Html.CheckBoxFor(m => m.Notification.Intial, new { @enabled = "enabled" }) Initial notification </label>
</div>
<div class="checkbox" id="update">
<label>
@Html.CheckBoxFor(m => m.Notification.Update) Update to an existing notification
</label>
</div>
<div class="checkbox" id="withdrawn">
<label>
@Html.CheckBoxFor(m => m.Notification.Withdrawn, new { @disabled = "disabled" }) The project has been withdrawn
</label>
</div>
<b>Details of the locations(s) of the site</b>
<div class="checkbox">
<label>
@Html.CheckBoxFor(m => m.Notification.MultiSite) Check this box if this project has multiple site locations
</label>
</div>
<p>What is the exact address ?</p>
<div class="form-group">
@Html.LabelFor(m => m.Notification.Address1)
@Html.TextBoxFor(m => m.Notification.Address1, new { @class = "form-control", placeholder = "(eg building name, address, location, grid ref)" })
@Html.ValidationMessageFor(m => m.Notification.Address1)
</div>
<div class="form-group">
@Html.LabelFor(m => m.Notification.Address2)
@Html.TextBoxFor(m => m.Notification.Address2, new { @class = "form-control", placeholder = "(eg street number, street name)" })
@Html.ValidationMessageFor(m => m.Notification.Address2)
</div>
<div class="form-group">
@Html.LabelFor(m => m.Notification.Address3)
@Html.TextBoxFor(m => m.Notification.Address3, new { @class = "form-control", placeholder = "(eg district)" })
</div>
<div class="form-group">
@Html.LabelFor(m => m.Notification.Town)
@Html.TextBoxFor(m => m.Notification.Town, new { @class = "form-control" })
@Html.ValidationMessageFor(m => m.Notification.Town)
</div>
<div class="form-group">
@Html.LabelFor(m => m.Notification.County)
@Html.TextBoxFor(m => m.Notification.County, new { @class = "form-control" })
</div>
<div class="form-inline">
<div class="form-group" id="postCodeField">
@Html.LabelFor(m => m.Notification.PostCode)
@Html.TextBoxFor(m => m.Notification.PostCode, new { @class = "form-control" })
@Html.ValidationMessageFor(m => m.Notification.PostCode)
</div>
<button type="submit" class="btn btn-primary" id="addressSearch">Search for Address</button>
</div>
<div class="form-inline">
<div class="form-group" id="submissionDropdown">
@Html.LabelFor(m => m.Notification.CountryId)
@Html.DropDownListFor(m => m.Notification.CountryId, new SelectList(Model.Countries, "Id", "Name"), "Please choose one", new { @class = "form-control" })
@Html.ValidationMessageFor(m => m.Notification.CountryId)
</div>
<div class="form-group" id="submissionDropdown">
@Html.LabelFor(m => m.Notification.AreaId)
@Html.DropDownListFor(m => m.Notification.AreaId, new SelectList(Model.Areas, "Id", "Name"), "Select Country first", new { @class = "form-control" })
@Html.ValidationMessageFor(m => m.Notification.AreaId)
</div>
<div class="form-group" id="submissionDropdown">
@Html.LabelFor(m => m.Notification.LocalId)
@Html.DropDownListFor(m => m.Notification.LocalId, new SelectList(Model.Locals, "Id", "Name"), "Select a Geographical Area first", new { @class = "form-control" })
@Html.ValidationMessageFor(m => m.Notification.LocalId)
</div>
</div>
@Html.HiddenFor(m => m.Notification.Id)
@Html.AntiForgeryToken();
<button type="submit" class="btn btn-primary" id="pageOneSubmit">Submit</button>
}
@section scripts
{
<script>
$(document).ready(function(){
$("#Notification_Update").on('change', function(){
$("#Notification_Withdrawn").removeAttr("disabled");
$("#Notification_Initial").removeAttr("enabled");
});
})
</script>
}
答案 0 :(得分:0)
包括jquery然后
<script>
$(document).ready(function(){
$("#Notification_Update").on('change', function(){
$("#Notification_Withdrawn").removeAttr("disabled");
$("#my_hidden_input_id").show();
});
});
</script>
更新
使用HTML帮助程序将自定义ID添加到HTML控件。
@Html.CheckBoxFor(m => m.Notification.Withdrawn,
new { @disabled = "disabled", @id="Withdrawn" })
@Html.CheckBoxFor(m => m.Notification.Update,
new { @id="Update" })