我正在做一个非常简单的验证,检查两个字段是否相等.不幸的是,它似乎不起作用(当它应该返回true时返回false).
这是jQuery(#profSet是主要形式):
//if either password field is filled, start trying to validate it
if($("#chpw").val() != "" || $("#chpw2").val() != "")
{
$("#profSet").validate({
rules: {
chpw2: {
equalTo: "#chpw"
}
}
});
if($("#profSet").valid())
{
$pv = 1;
}
else
{
$pv = 0;
}
}
Run Code Online (Sandbox Code Playgroud)
这是HTML:
<tr>
<td>Change Password</td><td><input type="password" id="chpw" name="chpw"/></td>
</tr>
<tr>
<td>Confirm Password</td><td><input type="password" id="chpw2" name="chpw2"/><br><label for="chpw2" class="error" generated="true"></label></td>
</tr>
Run Code Online (Sandbox Code Playgroud)
我想是类似的东西
[更新]:抱歉,假设的答案
<script type="text/javascript" src="scripts/jquery.js"></script>
<script type="text/javascript" src="scripts/jquery.validate.js"></script>
<script type="text/javascript">
$(function (){
$('#form').validate({
rules:{
chpw:{
required: true,
equalTo: '#chpw2'
}
},
messages:{
chpw:
{
required: "Password is required",
equalTo: "Password must be equal"
}
}}
)
})
</script>
<form id="form">
<tr>
<td>Change Password</td><td><input type="password" id="chpw" name="chpw"/></td>
</tr>
<tr>
<td>Confirm Password</td><td><input type="password" id="chpw2" name="chpw2"/><br><label for="chpw2" class="error" generated="true"></label></td>
</tr>
<input type="submit" name="submit" />
</form>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8417 次 |
| 最近记录: |