JavaScript以html格式生成密码

JavaScript以html格式生成密码,javascript,Javascript,通过单击html表单中的“生成”按钮自动生成密码。但是生成的密码应该来自开发人员已经给出的密码列表 <input name="password" type="text"> <input type="button" class="button" value="Generate" onClick="generate();"> <script> function randomPassword(length) { var passwords = ["text1",

通过单击html表单中的“生成”按钮自动生成密码。但是生成的密码应该来自开发人员已经给出的密码列表

<input name="password" type="text">
<input type="button" class="button" value="Generate" onClick="generate();">


<script>
function randomPassword(length) {
var passwords = ["text1","text2","text3"];
var pass = passwords[Math.floor(Math.random()*passwords.length)];
return pass;
}

function generate() {
myform.password.value = randomPassword(myform.length.value);
}
</script>

函数随机密码(长度){
var密码=[“text1”、“text2”、“text3”];
var pass=passwords[Math.floor(Math.random()*passwords.length)];
回程通行证;
}
函数生成(){
myform.password.value=随机密码(myform.length.value);
}

让passwordList是开发人员提供的示例密码列表,请将其替换为您的原始列表

密码输入字段的id为password

使用下面的代码用开发人员提供的密码列表中的随机密码填充该字段

Html:

<input id="password" type="password"/>    
document.getElementById("password").value =passwordList[Math.floor(Math.random()*passwordList.length)];
如果未使用jQuery:

<input id="password" type="password"/>    
document.getElementById("password").value =passwordList[Math.floor(Math.random()*passwordList.length)];
来看看

var pwd=$(“#pwd”)
变量按钮=$(“按钮”)
变量len=$(“#长度”)
变量A_Z=$(“#A-Z”)
变量a_z=$(“#a-z”)
var num=$(“#0-1”)
var sc=$(“#特殊卡”)
//句柄单击并添加类
按钮。打开(“单击”,函数(){
html(CreateRandomPassword(len.val()、A_Z.is(“:checked”)、A_Z.is(“:checked”)、num.is(“:checked”)、sc.val();
})
函数CreateRandomPassword(长度、isUpperAlpha、isLowerAlpha、isNumaric、SpecialChars)
{
var_allowedChars=“”;
如果(isUpperAlpha!=假)
_allowedChars+=“ABCDEFGHJKLMNOPQRSTUVXYZ”;
如果(IsLowralpha!=假)
_allowedChars+=“abcdefghijkmnopqrstuvwxyz”;
如果(isNumaric!=假)
_allowedChars+=“0123456789”;
_允许字符+=特殊字符;
如果(!长度)
长度=8
var chars=“”;
allowedCharCount=\u allowedChars.length;
如果(allowedCharCount==0)
返回“”;
对于(变量i=0;i
正文{
背景:#20262E;
填充:20px;
字体系列:Helvetica;
}
#横幅信息{
背景:#fff;
边界半径:4px;
填充:20px;
字体大小:25px;
文本对齐:居中;
过渡:均为0.2s;
保证金:0自动;
宽度:300px;
}
钮扣{
背景:#0084ff;
边界:无;
边界半径:5px;
填充:8px 14px;
字体大小:15px;
颜色:#fff;
}
#banner-message.alt{
背景:#0084ff;
颜色:#fff;
边缘顶端:40px;
宽度:200px;
}
#banner-message.alt按钮{
背景:#fff;
颜色:#000;
}
输入[类型=复选框]{
变焦:2;
}

密码

生成密码

长度
A-Z a-z 0-1 附加字符

应该提供一个简单的js等价物,因为这里没有标记jquery,而且OP可能是编程的新手。然而,我个人会让他更多地表达自己的想法,他到底做了什么,遇到了什么问题。thrash论坛与SO的唯一区别是Q/A的质量。我们应该避免回答“请为我这样做”的请求。只要我的两分钱。