猿问

关于复选框显示问题。

如何选择一个或者多个复选框的时候,数字显示在div中呢,思路比较乱,谢谢!

<!doctype html>

<html>

<head>

<meta charset="utf-8">

<title>无标题文档</title>

</head>

<body>

<input type="checkbox">123<br/>

<input type="checkbox">456<br/>

<input type="checkbox">789<br/>

<input type="checkbox">563<br/>

<input type="checkbox">156<br/>

<input type="checkbox">110<br/>


  <div style="width:290px; height:50px; border:1px solid;">

</div>

</body>

</html>




动漫人物
浏览 646回答 1
1回答

富国沪深

<!doctype html><html><head>&nbsp; <meta charset="utf-8">&nbsp; <title>无标题文档</title></head><body>&nbsp; <input type="checkbox" name="test" value="123">123&nbsp; <br/>&nbsp; <input type="checkbox" name="test" value="456">456&nbsp; <br/>&nbsp; <input type="checkbox" name="test" value="789">789&nbsp; <br/>&nbsp; <input type="checkbox" name="test" value="563">563&nbsp; <br/>&nbsp; <input type="checkbox" name="test" value="156">156&nbsp; <br/>&nbsp; <input type="checkbox" name="test" value="110">110&nbsp; <br/>&nbsp; <div style="width:290px; height:50px; border:1px solid;">&nbsp; </div>&nbsp; <script src="jquery.min.js"></script>&nbsp; <script type="text/javascript">&nbsp; //改这些复选框统一的name属性,比如name="test",加上对应的value值&nbsp; $('input[name=test]').change(function() {&nbsp; &nbsp; var arr = []&nbsp; &nbsp; $('input[name=test]:checked').each(function(i, v) {&nbsp; &nbsp; &nbsp; &nbsp; arr.push($(v).val())&nbsp; &nbsp; })&nbsp; &nbsp; $('div').html(arr.join(','))&nbsp; })&nbsp; </script></body></html>
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答