javascript实现两个数字进行组合

combination.jpgcombination.jpg

numcomb.jpgnumcomb.jpg

实现任意两个数字,前面数字与后面数字组合

<!DOCTYPE html>
<html lang="en">

<head>
          <meta charset="UTF-8">
          <meta http-equiv="X-UA-Compatible" content="IE=edge">
          <meta name="viewport" content="width=device-width, initial-scale=1.0">
          <title>Number-Combination</title>
</head>

<body>
          <input id="bnum" type="number" placeholder="请输入开始数字" />
          <input id="enum" type="number" placeholder="请输入结束数字" />
          <input type="button" id='calc' value="排列组合" />
          <script>

                    var btn = document.getElementById('calc')
                    btn.onclick = function () {
                              var beginnum = document.getElementById('bnum').value.toString();
                              var endnum = document.getElementById('enum').value.toString();
                              comb(beginnum, endnum)
                    }
                    function comb(a, b) {
                              this.a = a.split('');
                              this.b = b.split('');
                              var len = this.a.lenght * this.b.lenght;
                              var temp = new Array();
                              for (var o = 0; o < this.a.length; o++) {
                                        for (p = 0; p < this.b.length; p++) {
                                                  console.log(this.a[o] + this.b[p])
                                                  let newDiv = document.createElement("div");
                                                  let newContent = document.createTextNode(this.a[o] + this.b[p]);
                                                  newDiv.appendChild(newContent);
                                                  let currentDiv = document.getElementById("div1");
                                                  document.body.insertBefore(newDiv, currentDiv);
                                        }
                              }
                    }
          </script>
</body>

</html>