我需要在我的表单上单击某个单选按钮时显示某些文本框,否则文本框应保持隐藏状态。这是我所拥有的示例:
HTML:
Radio buttons:
<p>Show textboxes<input type="radio" name="radio1" value="Show" onClick="getResults()">Do nothing<input type="radio" name="radio1" value="Nothing"></p>
Textboxes:
<div class="text"><p>Textbox #1 <input type="text" name="text1" id="text1" maxlength="30"></p></div>
<div class="text"><p>Textbox #2 <input type="text" name="text2" id="text2" maxlength="30"></p></div>
jQuery:
$(document).ready(function() {
$(".text").hide()
function getResults() {
$(".text").show()
};
});
当我取出 .show() 代码时,文本框保持隐藏状态。我需要在选择带有 onClick 事件的单选按钮时显示它们。任何帮助将不胜感激。
最佳答案
Javascript
$(document).ready(function () {
$(".text").hide();
$("#r1").click(function () {
$(".text").show();
});
$("#r2").click(function () {
$(".text").hide();
});
});
HTML
<p>Show textboxes
<input type="radio" name="radio1" id="r1" value="Show">Do nothing
<input type="radio" name="radio1" id="r2" value="Nothing">
</p>Wonderful textboxes:
<div class="text">
<p>Textbox #1
<input type="text" name="text1" id="text1" maxlength="30">
</p>
</div>
<div class="text">
<p>Textbox #2
<input type="text" name="text2" id="text2" maxlength="30">
</p>
</div>
关于javascript - 基于单选按钮选择使用 jQuery 隐藏/显示文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22790767/