2 回答
TA贡献1828条经验 获得超3个赞
// function to return # of 'Yes's
function calculateSum() {
return $(".currentStepAnswer[value='Yes']:checked").length;
};
$(function() {
$(".currentStepAnswer").change(function() {
$("#fallRiskTotal").html(calculateSum().toFixed(1));
});
});
TA贡献1821条经验 获得超6个赞
考虑以下示例。
$(function() {
function calculateSum() {
return $(".currentStepAnswer[value='Yes']:checked").length;
}
function calculatePerc() {
var y = $(".currentStepAnswer[value='Yes']:checked").length;
var t = $("ul li").length;
return y / t;
}
$(".currentStepAnswer").change(function() {
$("#fallRiskTotal").html(calculateSum().toFixed(2) + " " + (calculatePerc() * 100).toFixed(2) + "%");
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul>
<li id="qid61915_1" value="11" style="margin: 20px 0px 30px 0px" required="true">Test Question
<div class="radio answerRadio width-70"><label><input type="radio" name="qid61915Radio_1"
id="aid73380_1" class="currentStepAnswer" value="Yes">Yes</label></div>
<div class="radio answerRadio width-70"><label><input type="radio" name="qid61915Radio_1"
id="aid73381_1" class="currentStepAnswer" value="No">No</label></div>
</li>
<li id="qid61915_2" value="12" style="margin: 20px 0px 30px 0px" required="true">Test Question
<div class="radio answerRadio width-70"><label><input type="radio" name="qid61915Radio_2"
id="aid73380_2" class="currentStepAnswer" value="Yes">Yes</label></div>
<div class="radio answerRadio width-70"><label><input type="radio" name="qid61915Radio_2"
id="aid73381_2" class="currentStepAnswer" value="No">No</label></div>
</li>
<li id="qid61915_3" value="13" style="margin: 20px 0px 30px 0px" required="true">Test Question
<div class="radio answerRadio width-70"><label><input type="radio" name="qid61915Radio_3"
id="aid73380_3" class="currentStepAnswer" value="Yes">Yes</label></div>
<div class="radio answerRadio width-70"><label><input type="radio" name="qid61915Radio_3"
id="aid73381_1" class="currentStepAnswer" value="No">No</label></div>
</li>
</ul>
<div id="fallRiskTotal"></div>
添加回答
举报