为了账号安全,请及时绑定邮箱和手机立即绑定

关于复选框显示问题。

关于复选框显示问题。

动漫人物 2018-08-04 05:10:48
如何选择一个或者多个复选框的时候,数字显示在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>
查看完整描述

1 回答

?
富国沪深

TA贡献1790条经验 获得超9个赞

<!doctype html>

<html>


<head>

  <meta charset="utf-8">

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

</head>


<body>

  <input type="checkbox" name="test" value="123">123

  <br/>

  <input type="checkbox" name="test" value="456">456

  <br/>

  <input type="checkbox" name="test" value="789">789

  <br/>

  <input type="checkbox" name="test" value="563">563

  <br/>

  <input type="checkbox" name="test" value="156">156

  <br/>

  <input type="checkbox" name="test" value="110">110

  <br/>

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

  </div>

  <script src="jquery.min.js"></script>

  <script type="text/javascript">

  //改这些复选框统一的name属性,比如name="test",加上对应的value值

  $('input[name=test]').change(function() {

    var arr = []

    $('input[name=test]:checked').each(function(i, v) {

        arr.push($(v).val())

    })

    $('div').html(arr.join(','))

  })

  </script>

</body>


</html>


查看完整回答
反对 回复 2018-09-25
  • 1 回答
  • 0 关注
  • 645 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信