前端小demo——用特殊符号拼接字符串

这里我用的是心形拼接输入的字符串

<!DOCTYPE html>
<html>

<head lang="en">
  <meta charset="UTF-8">
  <title></title>
  <style>
    input {
      width: 150px;
      height: 30px;
      background-color: #ccc;
    }

    #btn {
      background-color: red;
    }
  </style>
</head>

<body>
  <input type="button" value="拼接字符串" id="btn" />
  <input type="text" />
  <input type="text" />
  <input type="text" />
  <input type="text" />
  <input type="text" />
  <input type="text" />
  <!-- <script src="common.js"></script> -->
  <script>
    function zy$(id) {
      return document.getElementById(id)
    };

    //注册点击事件,添加事件处理函数
    zy$("btn").onclick = function () {
      var inputs = document.getElementsByTagName("input");
      var str = [];
      for (var i = 0; i < inputs.length; i++) {
        if (inputs[i].type == "text") {
          str.push(inputs[i].value);
        }
      }
      document.write("<h2>" + str.join("") + "</h2>")
    };
  </script>
</body>

</html>

猜你喜欢

转载自www.cnblogs.com/yuebanzhou/p/9133245.html