目前我正在使用 MVC asp.net 处理在线申请表。
这是我的表格。
我想要的是,当用户选择单个单选按钮时,应该禁用其他单选按钮文本字段。我设法在这里使用 JSFiddle 实现了这 一点。
我所做的是
1) 将我创建的 JSFiddle 中的编码复制到 MVC 视图中
@model Insurance.ViewModels.RegisterInfoPA
@{
ViewBag.Title = "Insert";
}
<h2>Insert Fire Insurance</h2>
<script>
$(".radioBtn").click(function () {
$("#reg_title").attr("disabled", true);
$("#reg_registerNm").attr("disabled", true); //Comp_Name//Name
$("#reg_identityNo").attr("disabled", true); //Ic_No//army//com_regis
$("#pinfo_gender").attr("disabled", true);
$("#busInfo_dateRegisCompany").attr("disabled", true);
$("#reg_dateCompRegis").attr("disabled", true); //DOB
$("#pinfo_occupation").attr("disabled", true);
$("#pinfo_maritalId").attr("disabled", true);
$("#busInfo_contactNm").attr("disabled", true);
$("#busInfo_natureBusiness").attr("disabled", true);
if ($("input[name=reg.identityId]:checked").val() == "1") {
$("#reg_title").attr("disabled", false);
$("#reg_identityNo").attr("disabled", false);
$("#pinfo_gender").attr("disabled", false);
$("#reg_dateCompRegis").attr("disabled", false);
$("#pinfo_maritalId").attr("disabled", false);
$("#pinfo_occupation").attr("disabled", false);
}
if ($("input[name=reg.identityId]:checked").val() == "2") {
$("#reg_registerNm").attr("disabled", false);
$("#busInfo_dateRegisCompany").attr("disabled", false);
$("#busInfo_natureBusiness").attr("disabled", false);
$("#busInfo_contactNm").attr("disabled", false);
}
});
</script>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<link href="~/Content/FlexiPA.css" rel="stylesheet" />
<fieldset>
<legend>register</legend>
<div class="flexiPAtitle">
<h3>
<b>
@Html.RadioButtonFor(model => model.reg.identityId, 1, new { @class = "radioBtn" })
Individual Applicant
@Html.RadioButtonFor(model => model.reg.identityId, 2, new { @class = "radioBtn" })
Company Application
@Html.HiddenFor(model=>model.reg.insuranceTypeId, 3)
</b>
</h3>
</div>
我将代码放在 @Html.BeginForm() 之前。但它不起作用。
2)所以我尝试将代码放入不同的js文件中,然后从视图中调用它
<h2>Insert Fire Insurance</h2>
<script src="~/Scripts/IndividualCompany.js"></script>
@using (Html.BeginForm())
{
它仍然无法正常工作。任何我做错的想法。如何在 MVC 中使用这个 jquery 代码,这让我很困惑,因为当我在 JSFiddle 中编写代码时一切正常,但在 MVC 中却不行。我还从 nuget 管理器安装了 Jquery 包。真的需要一些指导。
谢谢你。