我在下拉列表中隐藏元素时遇到问题。 我在该下拉列表中有3个项目: "未知&#34 ;, "女&#34 ;, "男性" 我想只显示"未知"当我点击其他下拉列表时,personTypeCode =" legal"
我试过这个,但它没有用
changeIDTypeVisibility: function () {
personTypeCode = $("#PersonTypeCode").val();
if (personTypeCode === "legal") {
$('#FirstName').attr('readonly', 'readonly');
// $('#LastName').attr('readonly', 'readonly');
$('#MiddleName').attr('readonly', 'readonly');
$('#FatherName').attr('readonly', 'readonly');
$('#MotherName').attr('readonly', 'readonly');
document.getElementById('selectIdHere').selectedIndex = 0;
CRTool.PersonDetails.getGenderElements().each(function (index, element) {
$('#GenderId').showHideDropdownOptions('2', false);
});
}
else {
// natural
CRTool.PersonDetails.getGenderElements().each(function (index, element) {
$(element).show();
});
}
},
@Html.LabelFor(m => m.IsNatural)
@if( Model.CanSave )
{
@(Html.Kendo().DropDownListFor(m => m.PersonTypeCode)
.BindTo(new[] { new { Id = "natural", Name = Resx.PersonDetails.Natural }, new { Id = "legal", Name = Resx.PersonDetails.Legal } })
.DataTextField("Name")
.DataValueField("Id")
.Events(events => events.Change("CRTool.PersonDetails.changeIDTypeVisibility")))
}
else
@if( Model.CanSave )
{
@Html.LabelFor(m => m.GenderId)
@(Html.Kendo().DropDownListFor(m => m.GenderId)
.BindTo(Model.GenderTypes)
.DataTextField("Name")
.DataValueField("Id")
)
}
else
{
if(Model.IsNatural){
@Html.LabelFor(m => m.GenderId)
<span class="readonly">@Html.DisplayDashFor(m => m.GenderName)</span>
}
@Html.LabelFor(m => m.IsNatural)
@if( Model.CanSave )
{
@(Html.Kendo().DropDownListFor(m => m.PersonTypeCode)
.BindTo(new[] { new { Id = "natural", Name = Resx.PersonDetails.Natural }, new { Id = "legal", Name = Resx.PersonDetails.Legal } })
.DataTextField("Name")
.DataValueField("Id")
.Events(events => events.Change("CRTool.PersonDetails.changeIDTypeVisibility")
)
)
}
@if( Model.CanSave )
{
@Html.LabelFor(m => m.GenderId)
@(Html.Kendo().DropDownListFor(m => m.GenderId)
.BindTo(Model.GenderTypes)
.DataTextField("Name")
.DataValueField("Id")
)
}
else
{
if(Model.IsNatural){
@Html.LabelFor(m => m.GenderId)
<span class="readonly">@Html.DisplayDashFor(m => m.GenderName)</span>
}
&#13;
答案 0 :(得分:0)
使用此代码$('#GenderId').eq(0).hide()