每次都有不同匹配的名称生成器

时间:2018-11-13 15:47:21

标签: javascript html

   var nameone = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"];

var nametwo = ["q", "w", "e", "r", "t", "y", "u", "i", "o", "p"];

function getNewName() {
  var nameone, nametwo}

for(var i =0;i<nameone.length;i++)

getNewName = Math.floor(Math.random()* nameone.length);
   <form>

<input type="number" name="number" >
<button onclick="getNewName">Submit</button>

</form>

1 个答案:

答案 0 :(得分:0)

也许你是这个意思?

var first = ["Graesin", "Jerry", "Tray", "Montrel", "Luke", "Max", "Alex", "Nina", "Austin", "Mike"];

var last = ["Brownell", "Songs", "Andersen", "Tyler", "Beha", "Delgado", "Kaur", "Adams", "Jones", "Harris"];

function getNewName() {
  var arr = [];
  var num = document.getElementById("num").value; // get the number of names
  for (var i = 0; i < num; i++) {
    arr.push(
      first[Math.floor(Math.random() * first.length)] + " " +
      last[Math.floor(Math.random() * last.length)]);
    document.getElementById("output").innerHTML = arr.join('<br/>'); // div
    document.getElementById("outputfield").value = arr.join('\n'); // textarea
  }
}
<form>
  <input type="number" id="num" min=1 max=20 />
  <button type="button" onclick="getNewName()">Submit</button>
  <div id="output"></div>

  <textarea id="outputfield"></textarea>

</form>