【发布时间】:2014-05-31 22:34:28
【问题描述】:
我想做的是创建一个包含三个是或否问题的问卷。如果所有三个问题都选择了“是”,那么我想要一个警报。如果有任何问题选择了“否”,那么我需要针对该问题的警报。我以为我拥有它,但我在某个地方错过了一些东西。你能帮忙吗?
<script type="text/javascript">
$(document).ready(function() {
$('#getAnswersButton').click(function(Submit) {
var groceryList = document.getElementsByName('groceryList');
var equipTimeline= document.getElementsByName('equipTimeline');
var whatTime= document.getElementsByName('whatTime');
if (groceryList[0].checked && equipTimeline[0].checked && whatTime[0].checked) {
alert("Great! You’re all set! Let’s start cooking! Just click the 'Next' button to continue.");
} else if (groceryList[1].checked) {
alert("Please select the 'Grocery List' link above and review the list to see what you may have missed.");
} else if (equipTimeline[1].checked) {
alert("Please select the 'Equip/Timeline' link above and make sure you have all of your tools.");
} else if (whatTime[1].checked) {
alert("Please select the 'Equip/Timeline' link above and make sure you have all of your tools.");
}
}
});
</script>
<div>
<form>
<ol>
<li><label for="ingredients">Do you have all of the ingredients listed on the grocery list?</label></li>
<p>
<input type="radio" id="ingredients" name="groceryList" value="Yes" /> Yes
<input type="radio" id="ingredients" name="groceryList" value="No" /> No
</p><br>
<li><label for="equip">Did you gather up all of the utensils, appliances, and tools that you will need to use?</label></li>
<p>
<input type="radio" id="equip" name="equipTimeline" value="Yes" /> Yes
<input type="radio" id="equip" name="equipTimeline" value="No" /> No
</p><br>
li><label for="timeToEat">What time are you preparing to serve dinner? You need to subtract a <b>minimum</b> of 3 hours from that time. Keep an eye on the clock! <i>(For example: if you are serving dinner at 7pm, then you should start preparing everything at 4pm.)</i></label></li>
<p>
<input type="radio" id="timeToEat" name="whatTime" value="Yes" /> Yes
<input type="radio" id="timeToEat" name="whatTime" value="No" /> No
</p><br>
</ol>
</form>
</div>
【问题讨论】:
-
您的问题在哪里?问题通常是以与编程有关的问号结尾的句子。现在你只有一个问题:“你能帮忙吗?”。答案是肯定的!请将您的规格发布到“do-my-work-for-me.com”网站,然后阅读:sscce.org 请提供简短、自包含、正确(可编译)的示例。并就该代码提出一个简短而具体的问题。
-
我很抱歉没有像你这么了解。我对此完全陌生,并试图自己解决。根据我所拥有的以及我在参考书中看到的内容,我认为我的代码可以工作。如果我和你一样理解这一切,我就会找出问题所在。话虽如此,我想弄清楚为什么我上面的脚本没有给我想要的结果。如果我对脚本的了解足以知道要求什么,我会给出非常 SSCCE。如果这么麻烦回答,请不要。
标签: javascript jquery input radio-button getelementsbyname