<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>val demo</title>
<script src="jquery.min.js"></script>
</head>
<body>
<div id="sums">
<input type="radio" name="radio" id="radio1" value="100">100</input>
<input type="radio" name="radio" id="radio2" value="150">150</input>
<input type="radio" name="radioone" id="radio3" value="101">101</input>
<input type="radio" name="radioone" id="radio4" value="102">102</input>
</div>
<p></p>
<p id="total_potential"></p>
<script>
$(document ).ready(function() {
$("input[type=radio]").change(function(){
var sum = 0;
$("#sums").find("input[type='radio']:checked").each(function (){sum += parseInt($(this).val(),10);});
$("#total_potential").text(sum);
});
});
</script>
</body>
</html>
将所选radio buttons的值相加
最新推荐文章于 2019-07-11 20:46:36 发布