jquery .show()不能处理ASP MVC 3字段集

下面是我用来遍历一组fieldset元素的jquery,并根据用户从一组单选按钮中的选择,决定哪一个应该是可见的,哪些应该被隐藏(当页面加载时它们都被隐藏)。 但是,我无法使用.show()方法。

jQuery的

 $(document).ready(function () { $('input[name=TransactionType]').change(function () { var radioValue = $(this); var elements = []; $('#RightDiv').children().each(function () { console.log(radioValue.attr('id') + " " + $(this).attr('id')); if (radioValue.attr('id') == $(this).attr('id')) { console.log('here'); $(this).show(); } else { $(this).hide(); } }); }); }); 

ASP MVC

 
@Html.RadioButton("TransactionType", false, new { @id = "Enroll" }) Enroll a Tax ID for EFT
@Html.RadioButton("TransactionType", false, new { @id = "New" }) New Tax ID Without EFT Enrollment
@Html.RadioButton("TransactionType", false, new { @id = "ModT" }) Modify EFT Information by Tax ID
@Html.RadioButton("TransactionType", false, new { @id = "ModA" }) Modify EFT Information by Agent ID
@Html.RadioButton("TransactionType", false, new { @id = "Clone" }) Clone EFT on to a Sub Agent ID
@Html.RadioButton("TransactionType", false, new { @id = "Unenroll" }) Unenroll EFT by Tax ID
</div
...
...
...
...
...

这是来自jquery循环的控制台读数的屏幕截图

在此处输入图像描述

更改visibility: hidden; 您要display: none;的字段集display: none;

这将解决您的问题。

jQuery.show()只知道如何根据API文档处理CSS的display属性,因此要使代码工作,你需要使用display:none; 而不是visibility:hidden; 或使用jQuery.attr()编辑样式属性。