下面是我用来循环浏览一组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 id="LeftDiv" style="width:450px;float:left;">
<fieldset style="width:350px;">
@Html.RadioButton("TransactionType", false, new { @id = "Enroll" }) Enroll a Tax ID for EFT <br />
@Html.RadioButton("TransactionType", false, new { @id = "New" }) New Tax ID Without EFT Enrollment <br />
@Html.RadioButton("TransactionType", false, new { @id = "ModT" }) Modify EFT Information by Tax ID <br />
@Html.RadioButton("TransactionType", false, new { @id = "ModA" }) Modify EFT Information by Agent ID <br />
@Html.RadioButton("TransactionType", false, new { @id = "Clone" }) Clone EFT on to a Sub Agent ID <br />
@Html.RadioButton("TransactionType", false, new { @id = "Unenroll" }) Unenroll EFT by Tax ID
</fieldset>
</div
<div id="RightDiv" style="width:420px;float:left;">
<fieldset id="Enroll" style="width:350px; visibility: hidden;">...</fieldset>
<fieldset id="New" style="width:350px; visibility: hidden;">...</fieldset>
<fieldset id="ModT" style="width:350px; visibility: hidden;">...</fieldset>
<fieldset id="Clone" style="width:350px; visibility: hidden;">...</fieldset>
<fieldset id="Unenroll" style="width:350px; visibility: hidden;">...</fieldset>
</div>
这是来自 jquery 循环的控制台读数的屏幕截图