jquery验证密码一致
时间: 2023-08-02 17:05:15 浏览: 43
你可以通过以下代码使用 jQuery 验证两个密码输入框的值是否一致:
```html
<form>
<label for="password">Password:</label>
<input type="password" id="password" name="password">
<br>
<label for="confirm_password">Confirm Password:</label>
<input type="password" id="confirm_password" name="confirm_password">
<br><br>
<button type="submit">Submit</button>
</form>
```
```javascript
$(document).ready(function() {
$('form').submit(function(event) {
var password = $('#password').val();
var confirm_password = $('#confirm_password').val();
if (password != confirm_password) {
alert("Passwords do not match.");
event.preventDefault();
}
});
});
```
在表单提交时,获取密码输入框的值,然后检查两个密码是否相同。如果不相同,弹出警告框并阻止表单提交。