$("#tournamentDesignTabs").tabs();
$("#tournamentDesign").validate();
$("#createTournament").click(function(){
if($("#tournamentDesign").validate()){
$.post(
"createTournament.php",
{tournamentName: $("#tournamentName").val(), district: $("#district").val(), region: $("#region").val(), location: $("#location").val(), date: $("#date").val(), time: $("#time").val(), logo: $("#logo").val()},
function(responseText){
$("#result").html(responseText);
},
"html" )
} else {
alert("oh no");
}
}
);
Run Code Online (Sandbox Code Playgroud)
以上是我用来验证一些表单信息然后将其输入数据库的脚本。我遇到的问题是验证函数在附加到跨度的点击事件处理程序时似乎没有做任何事情。我还注意到 onfocusout 似乎也不正常。关于我做错了什么的任何建议或想法。我知道我正确地包含了插件,因为当我提交表单时验证功能仍然有效。不过我更喜欢ajax。谢谢!
编辑:正如下面的一个答案所说,他们认为拥有 html 会有所帮助,所以这里是页面。每一点代码和内容。我知道它又脏又乱,但我正在学习,很快就会把它清理干净。反正这里是:
<!DOCTYPE HTML SYSTEM>
<html>
<head>
<title>Tournament Designer</title>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.21/themes/smoothness/jquery-ui.css" type="text/css" media="all" />
<link type="text/css" rel="stylesheet" href="stylesheet.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.js"></script>
<script type="text/javascript" src="jquery.ui.touch-punch.js"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.js"></script>
<script type="text/javascript" src="code.js"></script>
</head>
<body>
<div class="topBanner">Tournament Designer</div>
<br/>
<form id="tournamentDesign" method="post" …Run Code Online (Sandbox Code Playgroud)