我正在制作一个表格,并以此为指导计算选中的是或否的复选框。我可以得到号码,但它没有显示在输入字段中。我看到它更新查看带有萤火虫的代码。这是我缩减的测试代码。
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("input[value=Yes]").each(function () {
$(this).change(updateCountyes);
});
updateCountyes();
function updateCountyes () {
var countyes = $("input[value=Yes]:checked").size();
$("input#item11_number_1").text(countyes);
$("label#item11").toggle(countyes > 0);
};
$("input[value=No]").each(function () {
$(this).change(updateCountno);
});
updateCountno();
function updateCountno () {
var countno = $("input[value=No]:checked").size();
$("input#item12_number_1").text(countno);
$("label#item12").toggle(countno > 0);
};
});</script>
</head>
<body>
<input type="checkbox" value="Yes" />Yes
<input type="checkbox" value="No" />No
<input type="checkbox" value="Yes" />Yes
<input type="checkbox" value="No" />No
<div id="item11" class="fb-item fb-100-item-column">
<div class="fb-grouplabel">
<label style="display: inline;" id="item11_label_0">Yes</label>
</div>
<div class="fb-input-number">
<input type="number" autocomplete="off" data-hint="" placeholder="" step="1" max="999999999" min="0" id="item11_number_1" name="countyes">
</div>
</div>
<div id="item12" class="fb-item fb-100-item-column">
<div class="fb-grouplabel">
<label style="display: inline;" id="item12_label_0">No</label>
</div>
<div class="fb-input-number">
<input type="number" autocomplete="off" data-hint="" step="1" max="999999999" min="0" id="item12_number_1" name="countno">
</div>
</div>
</body>
</html>