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
</div
这是来自jquery循环的控制台读数的屏幕截图
更改visibility: hidden;
您要display: none;
的字段集display: none;
。
这将解决您的问题。
jQuery.show()
只知道如何根据API文档处理CSS的display
属性,因此要使代码工作,你需要使用display:none;
而不是visibility:hidden;
或使用jQuery.attr()
编辑样式属性。