Jquery表单验证插件不起作用

时间:2010-05-24 11:01:40

标签: javascript jquery

我尝试验证一个简单的表单但是Jquery验证

当我仅使用Button而不是提交

时,插件无法正常工作

按钮。 我不能使用那里的提交按钮,因为如果我使用提交

按钮提交表单后执行操作并转到

到默认页面,而我当前的表单来自Ajax。我是

对Jquery来说很新。请帮助它紧急...... 我在这里给出文件。 的index.html

<html>
<head>
<script src="jquery.js">
<script="jquery-validate-min.js">
<script="validation.js>
</head>
<body>
<form id="contact_form">
<table>
<tr><th>Name</th><td><input name="name" /></td></tr>
<tr><th>E Mail</th><td><input name="email" /></td></tr>
<tr><th><input type="button" name ="submit" id="form_sub" 

onclick="save"></th><td><input name="email" /></td></tr>
</table>
</form>
</body>
</html>

现在是validation.js文件

function save(){

$("#form_sub").click(function(){
$("#contact_form").validate({
'rules':{
'name':{
'required':true,
'minlength':5
},
'email':{
'required':true,
'email':true
}
}
})
}

当我们使用input type =“submit”时,一切正常 但是当我们使用input type =“button”

时它不起作用

任何想法如何解决这个问题? 我是Jquery的新手......请帮忙

2 个答案:

答案 0 :(得分:0)

使用jQuery,您不需要onclick。移除function save(){}onclick参数。

jquery中的

.click(...)onclick相同,因此在调用onclick时,您实质上是在注册另一个save()

答案 1 :(得分:0)

我正在做这个我最终做的是我在提交的表格中使用了提交。

Html.BeginForm("", "", FormMethod.Post , new { id = "myFormid", onSubmit="return false;"})

这会停止提交,但如果模型无效,它不会提供自动短路。

相关问题