如何对按钮进行编码,以便在单击特定值时存储,然后可以将其放入等式中以便稍后进行预测?这是JSfiddle链接到正在进行的工作,我们正在尝试编写一个应用程序来预测滑雪伤害并需要一些帮助!!!!!
http://jsfiddle.net/DYJkG/792/
HTML:
<h1>Personal information</h1>
<h2>gear</h2>
<div class="toggle-btn-grp">
<label onclick="1" id="helmet" value="1" class="toggle-btn"><input type="radio" name="group2"/>helmet</label>
<label onclick="" class="toggle-btn"><input type="radio" name="group2"/>hat</label>
<label onclick="" class="toggle-btn"><input type="radio" name="group2"/>nothing</label>
</div>
<h2>ability</h2>
<div class="toggle-btn-grp">
<label onclick="" class="toggle-btn"><input type="radio" name="group2"/>beginner</label>
<label onclick="" class="toggle-btn"><input type="radio" name="group2"/>intermediate</label>
<label onclick="" class="toggle-btn"><input type="radio" name="group2"/>advanced</label>
</div>
<h2>snow conditions</h2>
<div class="toggle-btn-grp joint-toggle">
<label onclick="" class="toggle-btn"><input type="radio" name="group3"/>hard packed</label><label onclick="" class="toggle-btn"><input type="radio" name="group3"/>powder</label><label onclick="" class="toggle-btn"><input type="radio" name="group3"/>ice</label>
</div>
<h2>weather</h2>
<div class="toggle-btn-grp cssonly">
<div><input type="radio" name="group4"/><label onclick="" class="toggle-btn">clear</label></div>
<div><input type="radio" name="group4"/><label onclick="" class="toggle-btn">partly cloudy</label></div>
<div><input type="radio" name="group4"/><label onclick="" class="toggle-btn">snowy</label></div>
</div>
<!-- Note: empty onclick attribue is there to fix iOS labels not being clickable to their input target -->
<input type="button" id="button" value="Find your precentage!" />
<input type="button" id="button2" value="Learn more" />
使用Javascript:
$(".toggle-btn:not('.noscript') input[type=radio]").addClass("visuallyhidden");
$(".toggle-btn:not('.noscript') input[type=radio]").change(function() {
if( $(this).attr("name") ) {
$(this).parent().addClass("success").siblings().removeClass("success")
} else {
$(this).parent().toggleClass("success");
}
});
var onClick = function() {
alert("87%");
};
$('#button').click(onClick);
$('#button2').click(function() {
alert('I have literally no idea what you selected but you should probably stay off of they hill');
});
答案 0 :(得分:1)
您可以选择以下内容:http://jsfiddle.net/RhnvU/3282/ 这将计算一个数字,您可以相对容易地将其转换为百分比。
<form id="myForm">
<input type="radio" name="radioName" value="1" /> 1 <br />
<input type="radio" name="radioName" value="2" /> 2 <br />
<input type="radio" name="radioName" value="3" /> 3 <br />
</form>
<br>
<form id="myForm2">
<input type="radio" name="radioName" value="1" /> 1 <br />
<input type="radio" name="radioName" value="2" /> 2 <br />
<input type="radio" name="radioName" value="3" /> 3 <br />
</form>
<button id="click">click to calculate</button>
的jQuery
$('#click').on('click', function() {
var a = parseInt($('input[name=radioName]:checked', '#myForm').val());
var b = parseInt($('input[name=radioName]:checked', '#myForm2').val());
var sum = a+b;
alert (sum);
});
答案 1 :(得分:0)
我和@Mikey一样:)在这里你有:
HTML:
<label><input type="radio" name="group1" value="10" id="Add" checked >1</label>
<label><input type="radio" name="group1" value="20" id="Remove">2</label>
<label><input type="radio" name="group2" value="30" id="Add" checked >3</label>
<label><input type="radio" name="group2" value="40" id="Remove">4</label>
<input type="button" id="submit" value="test"/>
JQUERY:
$('#submit').click(function() {
var group1 = $("input:radio[name='group1']:checked").val();
var group2 = $("input:radio[name='group2']:checked").val();
var total = parseInt(group1) + parseInt(group2);
alert(total);
});