javascript - 页面加载时表单中的随机文本
问题描述
嘿,我有一个表单可以在页面加载时自动授予随机数,但无论如何我可以让它授予随机字符,甚至授予数字和字符?
这是我得到的:
document.getElementById('Codefield').value = Math.floor(Math.random() * 1000000000000);
<form method='post' action='secret_code.php'>
<input type="text" name="" size="40" id="Codefield">
<input type="submit" class='side' value="Get Code" id="submit" name="submit">
</form>
解决方案
您可以通过以下代码来完成:
document.getElementById('Codefield').value = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
<form method='post' action='secret_code.php'>
<input type="text" name="" size="40" id="Codefield">
<input type="submit" class='side' value="Get Code" id="submit" name="submit">
</form>
推荐阅读
- windows - 如何编写 powershell 脚本来知道磁盘是基本的还是动态的?
- git - 仅从 git hub 下载特定文件夹
- javascript - Testing routes to give same results on every request chai/mocha
- c++ - 调整 Scatter Gather List 缓冲区地址和长度
- python - 使用 Python 写入目录中的所有 *.txt 文件
- flutter - 滚动在使用 ListView 创建的垂直列表中不起作用?
- javascript - 如何在当前 Web 应用程序的 iframe 中使用有效令牌?
- mysql - 在 Sequelize 中使用 MySQL FIELD 函数
- python-3.x - 如何将多个.py文件转换成.exe并依次运行?
- python - 在 Django 项目中安装 python 模块