这样做的目的是在选择单选按钮时在占位符 div 中显示文本。问题是我的 Jquery 编码很糟糕,而且不知道我到底在做什么。
html
<div>
<form>
<input id="one" class="menu" type="radio" name="option" value="first">Radio Button here
<input id="two" class="menu" type="radio" name="option" value="second">Another Radio button
<input id="three" class="menu" type="radio" name="option" value="third">Yet another radio button
</form>
</div>
<div class="placeholder">
</div>
Jquery
$(document).ready(function(e) {
$('.menu').click(function () {
if ("#one").checked {
$('.placeholder').html('<h3>Testing</h3>');
}if ("#two").checked {
$('.placeholder').html('<h3>Testing Testing</h3>');
}if ("#three").checked {
$('.placeholder').html('<h3>Testing Testing Testing</h3>');
}
});
});
注意:如果我同时选中所有三个单选按钮,我希望所有三个消息都出现。我注意到在 JSfiddle 中,我一次只能单击一个单选按钮。如果我单击另一个按钮,它将取消选中上一个按钮。我目前正在工作的网站上使用类似的代码,它允许我检查任意数量的内容。这是为什么?
网站正在使用单选按钮 - http://bitlamp.wctc.edu/~kschmelzer/js2/LLC/
我试图通过三个不同的“页面”检查选项(请注意,如果网站未加载,“页面”只是在按下按钮时隐藏/显示的 div。全部都在一页上)使用下一个按钮,然后在最后的第四页上,它显示所选单选按钮的内容(文本)。
感谢您的帮助!
最佳答案
存在一些语法错误,请参见:http://codepen.io/FuckingLunatic/pen/grvZyd
$('.menu').click(function () {
if ($("#one").is(":checked")) {
$('.placeholder').html('<h3>Testing</h3>');
}if ($("#two").is(":checked")) {
$('.placeholder').html('<h3>Testing Testing</h3>');
}if ($("#three").is(":checked")) {
$('.placeholder').html('<h3>Testing Testing Testing</h3>');
}
});
关于javascript - 使用单选按钮通过 Jquery 显示内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36573260/