我试图基于是/否单选按钮的选择结果隐藏部分,其中是是,否是假。如果用户选择一个按钮,则会显示在该字段中,但该字段会显示是或否,如果用户单击“否”,它也应该保持隐藏状态(不是)。谢谢你的帮助。
这是JQuery代码
$(document).ready(function () {
$('input[type="radio"]').click(function () {
if ($(this).prop('#ImportPartRadio', true)) {
$('#ImportPartQuestions').show();
}
else if ($(this).prop('#ImportPartRadio', false)){
$('#ImportPartQuestions').hide();
}
});
});
这是div部分
@*import parts radio button*@
<div class="span-18 last" id="ImportPart">
<table class="item-display">
<tr>
<td class="label required" id="ImportPartRadio">
<div class='tooltip'>Is this an import part?<span class="tooltiptext">This information can be used to calssify the part for US Customs purposes.</span></div></td>
<td class="value" colspan="5">
Yes: @Html.RadioButtonFor(model => model.ImportPart, true)
No: @Html.RadioButtonFor(model => model.ImportPart, false)
</td>
</tr>
</table>
</div>
@*This table is for full procurement and sales procurement setup only*@
<div class="span-18 last" id="ImportPartQuestions">
<table class="item-display">
<tr>
<td class="label">If an import, what is the material and function of part?</td>
<td colspan="5" class="value">
@Html.TextAreaFor(model => model.MaterialAndFunction, new { @placeholder = "Description Here", maxLength = 300 })
@Html.ValidationMessageFor(model => model.MaterialAndFunction)
</td>
</tr>
</table>
</div>
我已经搜查了好几个小时,似乎找不到解决方案,这与他们中的任何一个都可以充分发挥作用一样接近。
$(document).ready(function() {
$('input[name="ImportPart"]').change(function() {
var radioValue = $(this).val();
var questionsDiv = $('#ImportPartQuestions');
if (radioValue == "True") {
questionsDiv.show();
} else {
questionsDiv.hide();
}
});
});
或使用 .toggle( display )
$('input[name="ImportPart"]').change(function() {
$('#ImportPartQuestions').toggle(this.value === "True");
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句