需要使用JavaScript设置最小字符数的帮助吗
我试图为密码字段设置至少5个字符,但它不起作用。每当我输入0或1个字符时,它都可以工作,但当输入2到5个字符时,挑战无法工作。有人能看看我有什么,告诉我哪里出了问题吗需要使用JavaScript设置最小字符数的帮助吗,javascript,validation,minimum,Javascript,Validation,Minimum,我试图为密码字段设置至少5个字符,但它不起作用。每当我输入0或1个字符时,它都可以工作,但当输入2到5个字符时,挑战无法工作。有人能看看我有什么,告诉我哪里出了问题吗 <fieldset> <legend>Password</legend> <label>Create Password</label> <input type="password" name="password" id"passw
<fieldset>
<legend>Password</legend>
<label>Create Password</label>
<input type="password" name="password" id"password"><br /><br />
<label>Confirm Password</label>
<input type="password" name="confirmPassword" id="confirmPassword">
</fieldset><br />
if (document.sample.password.value <=5) {
alert("Password must contain 5 characters.");
document.sample.password.select();
document.sample.password.style.backgroundColor="yellow";
return true; // leave now
}
密码
创建密码
确认密码
如果(document.sample.password.value将其更改为:
<fieldset>
<legend>Password</legend>
<label>Create Password</label>
<input type="password" name="password" id="password"><br /><br />
<label>Confirm Password</label>
<input type="password" name="confirmPassword" id="confirmPassword">
</fieldset><br />
if (document.getElementById('password').length<=5) {
alert("Password must contain 5 characters.");
document.getElementById('password').select();
document.getElementById('password').style.backgroundColor="yellow";
return true; // leave now
}
密码
创建密码
确认密码
if(document.getElementById('password').length感谢您的帮助。不幸的是,它仍然不起作用。这是我现在拥有的。if(document.getElementById('password').length密码创建密码
确认密码