Javascript 重新加载时随机输入(HTML)中的文本(JS)

Javascript 重新加载时随机输入(HTML)中的文本(JS),javascript,html,Javascript,Html,我想随机化字母和数字,比如 设r=Math.random().toString(36).子字符串(7); 控制台日志(“随机”,r) 但将其插入文本输入HTML字段中。我已经设法从一个列表中插入文本,但我希望它完全随机,并跟随@something.com 例如,我希望输入字段在每次刷新时具有如下内容: 8ut5fgh8@gmail.com 0okmnhy4@gmail.com s5g7j9l0@gmail.com @gmail.com前的字符长度应为8个字符 谢谢你的帮助。这是我已经做过的事情的

我想随机化字母和数字,比如

设r=Math.random().toString(36).子字符串(7);
控制台日志(“随机”,r)

但将其插入文本输入HTML字段中。我已经设法从一个列表中插入文本,但我希望它完全随机,并跟随@something.com

例如,我希望输入字段在每次刷新时具有如下内容:

8ut5fgh8@gmail.com

0okmnhy4@gmail.com

s5g7j9l0@gmail.com

@gmail.com前的字符长度应为8个字符

谢谢你的帮助。这是我已经做过的事情的一小部分”

var文本=[
“@gmail.com”,
“@yahoo.com”,
“@xdxd.com”
];
document.getElementById('email0')。value=text[Math.floor(Math.random()*text.length)];

电子邮件:

如果你知道如何制作一个域的一部分,那么通过类比来完成剩下的部分

var文本=[
“@gmail.com”,
“@yahoo.com”,
“@xdxd.com”
];
var chars=['a',b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','v','w','s','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','r','s','t','u','v','w','x','y','s','z','1','2','3','4','5','6','7','8','
电子邮件功能(长度){
让结果=“”
对于(设i=0;i你可以试试这个

var文本=[
“@gmail.com”,
“@yahoo.com”,
“@xdxd.com”
];
函数随机(){
var text=“”;
var ch=“abcdefghijklmnopqrstuvxyzabefghijklmnopqrstuvxyzo123456789”;
对于(变量i=0;i<8;i++)
text+=ch.charAt(Math.floor(Math.random()*ch.length));
返回文本;
}
设str=random()+text[Math.floor(Math.random()*text.length)];
document.getElementById('email0')。value=str

这是另一种使用数组和连接的方式,假设您只希望随机电子邮件中包含小写字母

let texts = [
  "@gmail.com",
  "@yahoo.com",
  "@xdxd.com"
];
let alphnum = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
let randomChoice = [texts[Math.floor(Math.random() * texts.length)]]

for (let index = 0; index < 8; index++) {
  const element = alphnum[Math.floor(Math.random() * alphnum.length)];
  randomChoice.unshift(element)
}
let randomChoiceString = randomChoice.join("")

document.getElementById('email0').value = randomChoiceString
let text=[
“@gmail.com”,
“@yahoo.com”,
“@xdxd.com”
];
设alphnum=[“a”、“b”、“c”、“d”、“e”、“f”、“g”、“h”、“i”、“j”、“k”、“l”、“m”、“n”、“o”、“p”、“q”、“r”、“s”、“t”、“u”、“v”、“w”、“x”、“y”、“z”、“0”、“1”、“2”、“3”、“4”、“5”、“6”、“7”、“8”、“9”]
让randomChoice=[text[Math.floor(Math.random()*text.length)]]
对于(让索引=0;索引<8;索引++){
常量元素=alphnum[Math.floor(Math.random()*alphnum.length)];
randomChoice.unshift(元素)
}
让randomChoiceString=randomChoice.join(“”)
document.getElementById('email0')。value=randomChoiceString

你真是个天才。谢谢