0

如何根据人们的单选按钮选择向此测验添加不同的结果?这是测验:

 <html>
 <head></head>
 <body>
 <h1></h1>
 <form>
 <ol>
 <li> How much are you willing to spend on a phone per month?</li>
 <ul>
 <li> <input type = "radio" name = "q1"> £5-£10.</input></li>
 <li> <input type = "radio" name = "q1"> £10-£15.</input></li>
 <li> <input type = "radio" name = "q1"> £15-£20.</input></li>
 <li> <input type = "radio" name = "q1"> £20-£25.</input></li>
 <li> <input type = "radio" name = "q1"> £25-£30.</input></li>
 <li> <input type = "radio" name = "q1"> £30-£35.</input></li>
 <li> <input type = "radio" name = "q1"> £35-£40.</input></li>
 </ul>
 <li> Are you good with technology?</li>
 <ul>
 <li> <input type = "radio" name = "q2"> Yes.</input></li>
 <li> <input type = "radio" name = "q2"> No.</input></li>
 </ul>
 <li> Are you looking for an easy to use phone?</li>
 <ul> 
 <li> <input type = "radio" name = "q3"> Yes.</input></li>
 <li> <input type = "radio" name = "q3"> No.</input></li>
 </ul>
 <li> Are you looking for a modern type of phone?</li>
 <ul>
 <li> <input type = "radio" name = "q4"> Yes.</input></li>
 <li> <input type = "radio" name = "q4"> No.</input></li>
 </ul>
 <li> How big do you want the phone to be?</li>
 <ul>
 <li> <input type = "radio" name = "q5"> Big.</input></li>
 <li> <input type = "radio" name = "q5"> Medium.</input></li>
 <li> <input type = "radio" name = "q5"> Small.</input></li>
 <li> <input type = "radio" name = "q5"> I don't really mind.</input></li>
 </ul>
 <li> Do you care about the colour of the phone?</li>
 <ul>
 <li> <input type = "radio" name = "q6"> Yes.</input></li>
 <li> <input type = "radio" name = "q6"> No.</input></li>
 </ul>
 <li> Have you ever owned a phone before?</li>
 <ul>
 <li> <input type = "radio" name = "q7"> Yes.</input></li>
 <li> <input type = "radio" name = "q7"> No.</input></li>
 </ul>
 <li> Do you want to be able to use the phone to get out of awkward social situations?</li>
 <ul>
 <li> <input type = "radio" name = "q8"> Yes.</input></li>
 <li> <input type = "radio" name = "q8"> No.</input></li>
 </ul>
 <li> Do you want to be able to access an app store and download apps using your phone?</li>
 <ul>
 <li> <input type = "radio" name = "q9"> Yes.</input></li>
 <li> <input type = "radio" name = "q9"> No.</input></li>
 </ul>
 <li> What happened to the last phone you owned?</li>
 <ul>
 <li> <input type = "radio" name = "q10"> I got bored of it.</input></li>
 <li> <input type = "radio" name = "q10"> It broke(I'm clumsy).</input></li>
 <li> <input type = "radio" name = "q10"> It broke.</input></li>
 <li> <input type = "radio" name = "q10"> The contract ran out.</input></li>
 <li> <input type = "radio" name = "q10"> Other.</input></li>
 </ul>
 </ol>
 <input type = "button" value = "Submit"></input> <input type = "reset" value = "Clear"></input>
 <textarea>The right phone for you will be displayed here.</textarea> 



 </html>

我正在尝试做的事情可能吗?多年来,我一直在努力寻找这个问题的答案。如果你知道我怎么能做我所描述的,请说。谢谢阅读。

4

1 回答 1

3

使用javascript从html中提取信息,然后得到总和。您可以使用 jquery/ajax 来执行此操作,而无需提交页面。

顺便说一句,您是什么意思添加测验的结果?

更新于 2013 年 10 月 13 日

使用 javascript 本身并在前端进行。

首先,将每个单选按钮更改为:

<li><input type = "radio" id = "q1" value="5-10" name = "q1"> £5-£10.</input></li>

并使用 JDOM 获取值

var name = document.getElementById('q1').value;//name will equal to "5-10"

获得所有选项值后,您可以在逻辑中做任何您想做的事情希望它有所帮助。

于 2013-10-12T22:16:31.050 回答