我有一个代码来计算所选的复选框,并在div中显示它们。我尝试了不同的事情而没有成功,我想要实现的目标如下:填充textarea时(文本长度> 1) - >将1添加到结果中。当用户键入某些内容(它应该是实时)时,将1添加到结果中;当用户删除textarea中的所有内容时,删除1。计算所选复选框(CodePen)$('input[type="checkbox"]').change(function() { var selected = 0; var number_of_checkboxes = $('input[type="checkbox"]:checked').length; selected += number_of_checkboxes; $('#result').html(selected);});<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><div class="answers"> <label for="text1"> <input type="checkbox" name="text1" id="text1" value="1"> <span>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </span> </label> <br> <label for="text2"> <input type="checkbox" name="text2" id="text2" value="1"> <span>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </span> </label> <br> <label for="text3"> <input type="checkbox" name="text3" id="text3" value="1"> <span>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </span> </label> <br> <br> <textarea id="selected" minlength="20" name="selected" placeholder="Lorem ipsum dolor sit amet" style="width: 500px; height: 100px;"></textarea> <div id="result">0</div></div>
添加回答
举报
0/150
提交
取消