jQuery表单验证不需要';行不通
我正在进行一个简单的表单验证,它简单地检查高度字段是否已填充。我已经仔细检查了代码中的所有内容,但我找不到它为什么不工作 我的HTML:jQuery表单验证不需要';行不通,jquery,forms,validation,Jquery,Forms,Validation,我正在进行一个简单的表单验证,它简单地检查高度字段是否已填充。我已经仔细检查了代码中的所有内容,但我找不到它为什么不工作 我的HTML: <form id="configuration" action=""> <div class="con_near"> <label for="height">height: (mm)</label> <input id="form_height" name="height"
<form id="configuration" action="">
<div class="con_near">
<label for="height">height: (mm)</label>
<input id="form_height" name="height" maxlength="4" type="text" />
</div><!--End con_near-->
<input name="calculated" type="submit" class="submit" value="Calculate" />
</form>
高度:(毫米)
我的jQuery:
<script>
$(document).ready(function(){
// Form validation
var configForm = $("#configuration");
var height = $("#form_height");
// On blur
height.blur(validateHeight);
// On keyup
height.keyup(validateHeight);
configForm.submit(function(){
if(validateHeight())
return true;
else
return false;
});
function validateHeight() {
if(height.val().length() < 4) {
height.addClass("red_border");
return false;
}
else{
height.removeClass("red_border");
return true;
}
}
});
</script>
$(文档).ready(函数(){
//表单验证
var configForm=$(“#配置”);
变量高度=$(“#形式高度”);
//关于模糊
高度。模糊(验证高度);
//关于keyup
高度。键控(验证高度);
configForm.submit(函数(){
if(validateHeight())
返回true;
其他的
返回false;
});
函数validateHeight(){
if(height.val().length()<4){
高度。addClass(“红色边框”);
返回false;
}
否则{
高度。移除类(“红色边框”);
返回true;
}
}
});
长度不是一个函数,而是一个属性
试一试
configForm.submit(函数(){
如果(高度)
返回true;
其他的
返回false;
});
功能验证高度(高度){
如果(高度.val().长度<4){
高度。addClass(“红色边框”);
返回false;
}
否则{
高度。移除类(“红色边框”);
返回true;
}
}
长度不是一个函数,而是一个属性
试一试
configForm.submit(函数(){
如果(高度)
返回true;
其他的
返回false;
});
功能验证高度(高度){
如果(高度.val().长度<4){
高度。addClass(“红色边框”);
返回false;
}
否则{
高度。移除类(“红色边框”);
返回true;
}
}
长度不是一个函数,而是一个属性
试一试
configForm.submit(函数(){
如果(高度)
返回true;
其他的
返回false;
});
功能验证高度(高度){
如果(高度.val().长度<4){
高度。addClass(“红色边框”);
返回false;
}
否则{
高度。移除类(“红色边框”);
返回true;
}
}
长度不是一个函数,而是一个属性
试一试
configForm.submit(函数(){
如果(高度)
返回true;
其他的
返回false;
});
功能验证高度(高度){
如果(高度.val().长度<4){
高度。addClass(“红色边框”);
返回false;
}
否则{
高度。移除类(“红色边框”);
返回true;
}
}
问题出在这里.length()
使用
if(height.val().length<4){
而不是
if(height.val().length() < 4) {
if(height.val().length()<4){
问题出在这里.length()
使用
if(height.val().length<4){
而不是
if(height.val().length() < 4) {
if(height.val().length()<4){
问题出在这里.length()
使用
if(height.val().length<4){
而不是
if(height.val().length() < 4) {
if(height.val().length()<4){
问题出在这里.length()
使用
if(height.val().length<4){
而不是
if(height.val().length() < 4) {
if(height.val().length()<4){
使用length
代替length()
if(height.val().length<4){
代替
if(height.val().length()<4){
功能验证高度(高度){
如果(高度.val().长度<4){
.....
使用length
代替length()
类似
if(height.val().length<4){
代替
if(height.val().length()<4){
功能验证高度(高度){
如果(高度.val().长度<4){
.....
使用length
代替length()
类似
if(height.val().length<4){
代替
if(height.val().length()<4){
功能验证高度(高度){
如果(高度.val().长度<4){
.....
使用length
代替length()
类似
if(height.val().length<4){
代替
if(height.val().length()<4){
功能验证高度(高度){
如果(高度.val().长度<4){
.....
提交事件不会因返回false而停止。您需要使用preventDefault()停止事件。请尝试以下代码
configForm.submit(function(e){
if(!validateHeight())
e.preventDefault();
});
function validateHeight() {
if(height.val().length < 4) { // <- here you also made a mistake in length its a property not a function
height.addClass("red_border");
return false;
}
height.removeClass("red_border");
return true;
}
configForm.submit(函数(e){
如果(!validateHight())
e、 预防默认值();
});
函数validateHeight(){
如果(height.val().length<4){/提交事件不会因返回false而停止,则需要使用preventDefault()停止事件,请尝试以下代码
configForm.submit(function(e){
if(!validateHeight())
e.preventDefault();
});
function validateHeight() {
if(height.val().length < 4) { // <- here you also made a mistake in length its a property not a function
height.addClass("red_border");
return false;
}
height.removeClass("red_border");
return true;
}
configForm.submit(函数(e){
如果(!validateHight())
e、 预防默认值();
});
函数validateHeight(){
如果(height.val().length<4){/提交事件不会因返回false而停止,则需要使用preventDefault()停止事件,请尝试以下代码
configForm.submit(function(e){
if(!validateHeight())
e.preventDefault();
});
function validateHeight() {
if(height.val().length < 4) { // <- here you also made a mistake in length its a property not a function
height.addClass("red_border");
return false;
}
height.removeClass("red_border");
return true;
}
configForm.submit(函数(e){
如果(!validateHight())
e、 预防默认值();
});
函数validateHeight(){
如果(height.val().length<4){/提交事件不会因返回false而停止,则需要使用preventDefault()停止事件,请尝试以下代码
configForm.submit(function(e){
if(!validateHeight())
e.preventDefault();
});
function validateHeight() {
if(height.val().length < 4) { // <- here you also made a mistake in length its a property not a function
height.addClass("red_border");
return false;
}
height.removeClass("red_border");
return true;
}
configForm.submit(函数(e){
如果(!validateHight())
e、 预防默认值();
});
函数validateHeight(){
如果(height.val()
$(document).ready(function(){
// Form validation
var configForm = $("#configuration");
var height = $("#form_height");
// On blur
height.blur(validateHeight);
// On keyup
height.keyup(validateHeight);
configForm.submit(function(){
return validateHeight();
});
function validateHeight() {
if(height.val().length < 4) {
height.addClass("red_border");
return false;
}
else{
height.removeClass("red_border");
return true;
}
}
});
$(文档).ready(函数(){
//表单验证
var configForm=$(“#配置”);
变量高度=$(“#形式高度”);
//关于模糊
高度。模糊(验证高度);
//关于keyup
高度。键控(验证高度);
configForm.submit(函数(){
返回validateHeight();
});
函数validateHeight(){