【发布时间】:2016-09-26 00:14:58
【问题描述】:
我正在为我正在构建的 RPG 网站制作多项选择题。
我需要脚本来做两件事。
检查是否所有 14 个问题都已回答,如果回答了,则显示提交按钮!
检查以查看已检查的答案,然后将分数添加到各种变量中。
在这两种情况下,我都需要至少可以与单选按钮联系的脚本,但可惜的是,我的新手代码技能还不够。
这里是 HTML
<div class="question">
<form>
<p class="bold">1. At a party, your with your buddies and a drunken fool does something to seriously offend you. Your friends look to see how you'll respond. What do you do? </p>
<ul>
<li class="answer mnkA"><input type="radio" name="answer">A. Laugh it off, hes drunk, its really not worth getting upset over</li>
<li class="answer cleA"><input type="radio" name="answer">B. Just because your drunk doesn't excuse you from responsibilities, that person should apologize</li>
<li class="answer berA"><input type="radio" name="answer">C. I'm not gonna let him make a fool of me in front of my friends, I have beat whole sale ass for less then that before!</li>
<li class="answer mgeA"><input type="radio" name="answer">D. I'll get my revenge, I caught him in the bathroom earlier doing something embarrassing. Might just let that slip.</li>
<li class="answer thfA"><input type="radio" name="answer">E. I am gonna wait for this fool to turn his back, then he'll get whats coming to him.</li>
<li class="answer defA"><input type="radio" name="answer">F. I'll get rough if he keeps pushing it. My main concern is my friends that I'm here with tonight.</li>
<li class="answer druA"><input type="radio" name="answer">G. I'm gonna keep my eyes open but not snap judge. Stay open, if he wants to throw down ill throw down, if he wants to talk it out , ill listen.</li>
<li class="answer rngA"><input type="radio" name="answer">H. I'm gonna leave, sometimes avoidance is the best answer</li>
</ul>
</form>
</div>
这是我昨晚在 Stack Overflow 上搜索了一段时间后尝试的 jQuery。
(我创建了一个小测试按钮,我没有包含它,通过 onclick 来调用此函数)
$('#testbutton').on('click', function(){
if ($('input[name=answer]:checked' == true)) {alert("its checked")} else {alert("not checked")};
});
无论是选中、未选中还是部分选中所有按钮,它始终返回 true。我知道我在这里一定做错了什么。另外我不想给元素本身一个选中的属性,因为我不希望它默认读取为选中,以防有人跳过问题,它会给出倾斜的结果(我认为)
【问题讨论】:
-
有一个错字。
==true应该在 if 条件中的 jQuery 选择器之外。它应该是$('input[name=answer]:checked') == true不确定这是帖子中的错字还是实际代码中的错字
标签: jquery button radio checked