zoukankan      html  css  js  c++  java
  • checkbox:click事件触发span元素内容改变

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>checkbox</title>
        <script src="jquery.js"></script>
    </head>
    <body>
    <p>我想去<span id="spanId">_____</span></p>
    <form action="#" id="form">
        <input type="checkbox" name="city" value="南京">南京
        <input type="checkbox" name="city" value="北京">北京
        <input type="checkbox" name="city" value="纽约">纽约
    </form>
    <script>
            $(function () {
                $("input[name=city]").click(function () {
                    var arr = [];
                    $("input[name=city]").each(function () {
                        if(this.checked){
                            arr.push(this.value);
                        }else{
                            var index = arr.indexOf(this.value);
                            if(index != -1){
                                arr[index] = "";
                            }
                        }
                    });
                    $("#spanId").text(arr.join(","));
                })
            });
    </script>
    </body>
    </html>
  • 相关阅读:
    day74test
    day73
    drf节流
    drf面试题及总结
    day72test
    日常积累
    windows 内核下获取进程路径
    转:浅析C++中的this指针
    vc 获取窗口标题GetWindowText
    驱动自定义回调例程
  • 原文地址:https://www.cnblogs.com/sunxirui00/p/7500844.html
Copyright © 2011-2022 走看看