gpt4 book ai didi

javascript - 通过下拉选择禁用/启用输入字段 mvc 4

转载 作者:行者123 更新时间:2023-12-01 05:44:19 25 4
gpt4 key购买 nike

我正在尝试创建 ASP.NET MVC 4 Internet 应用程序,在该应用程序中我有注册 View ,根据 Angular 色的选择,它应该能够禁用注册表中的几个输入字段,

例如:当用户选择高等教育委员会时,它将能够禁用“University”、“Direct_Number”、“Mobile”字段

这是我的 CSHTML 代码,包括 Jquery

@model AFFEMS2_HEC.Models.RegisterViewModel

@{
ViewBag.Title = "HEI_Registration";
Layout = "~/Views/Shared/_HEI_Registration.cshtml";
}


}

<hgroup class="title">
<h1>@ViewBag.Title.</h1>
<h2>Add New Higher Education Institute</h2>
</hgroup>

@using (Html.BeginForm()) {
@Html.AntiForgeryToken()
@Html.ValidationSummary()

<fieldset>
<legend>Registration Form</legend>
<ol>
<div class="editor-label">
@Html.LabelFor(model => model.RoleName,"Please Select Type of the Role ")
<br/>
</div>
<div>
@Html.DropDownListFor(model => model.RoleName,
new SelectList(
new List<Object>{
new { value = "" , text = "Select" },
new { value = "HEC_Admin" , text = "Higher Edcuation Council" },
new { value = "HEI_User" , text = "Higher Education Institute"}
}, "value", "text", "-"), new { id = "allDay" })
@Html.ValidationMessageFor(model => model.RoleName)

</div>

<div class="editor-label">
@Html.LabelFor(model => model.UserName)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.UserName)
@Html.ValidationMessageFor(model => model.UserName)
</div>

<div class="editor-label">
@Html.LabelFor(model => model.University)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.University ,new { id = "University" })
@Html.ValidationMessageFor(model => model.University)
</div>

<div class="editor-label">
@Html.LabelFor(model => model.Title)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Title)
@Html.ValidationMessageFor(model => model.Title)
</div>

<div class="editor-label">
@Html.LabelFor(model => model.First_Name)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.First_Name)
@Html.ValidationMessageFor(model => model.First_Name)
</div>


<div class="editor-label">
@Html.LabelFor(model => model.Last_Name)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Last_Name)
@Html.ValidationMessageFor(model => model.Last_Name)
</div>

<div class="editor-label">
@Html.LabelFor(model => model.Email)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Email)
@Html.ValidationMessageFor(model => model.Email)
</div>

<div class="editor-label">
@Html.LabelFor(model => model.Direct_Number)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Direct_Number ,new { id = "Direct_Number" })
@Html.ValidationMessageFor(model => model.Direct_Number)
</div>

<div class="editor-label">
@Html.LabelFor(model => model.Mobile)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Mobile ,new { id = "Mobile" })
@Html.ValidationMessageFor(model => model.Mobile)
</div>

<div class="editor-label">
@Html.LabelFor(model => model.Password)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Password)
@Html.ValidationMessageFor(model => model.Password)
</div>

<div class="editor-label">
@Html.LabelFor(model => model.ConfirmPassword)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ConfirmPassword)
@Html.ValidationMessageFor(model => model.ConfirmPassword)
</div>


</ol>
<input type="submit" value="Register" />
</fieldset>
}

@section Scripts {
@Scripts.Render("~/bundles/jqueryval")

<script>
$("#allDay").change(function () {
if ($(this).val() == "HEC_Admin") {
$("#University").attr("disabled", true);
$("#Direct_Number").attr("disabled", true);
$("#Mobile").attr("disabled", true);
}
if ($(this).val() == "HEI_User") {
$("#University").attr("disabled", false);
$("#Direct_Number").attr("disabled", false);
$("#Mobile").attr("disabled", false);
}

});

</script>
}

似乎不起作用,感谢有人可以提供帮助

最佳答案

试试这个

           if ($(this).val() == "HEC_Admin") {
$("#University").attr("disabled", "disabled");
$("#Direct_Number").attr("disabled", "disabled");
$("#Mobile").attr("disabled", "disabled");
}
if ($(this).val() == "HEI_User") {
$("#University").removeAttr("disabled");
$("#Direct_Number").removeAttr("disabled");
$("#Mobile").removeAttr("disabled");
}

关于javascript - 通过下拉选择禁用/启用输入字段 mvc 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28342582/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com