我的站点上有一个简单的表单,它通过 Ajax 向它发送数据,然后向下滑动一条消息。发送工作正常,消息向下滑动,但验证部分不起作用。如果用户根本没有向该字段填写任何内容,我希望它显示警报。
这是整个代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Coming Soon!</title>
<!-- Our CSS stylesheet file -->
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans+Condensed:300" />
<link rel="stylesheet" href="assets/css/styles.css" />
<link rel="stylesheet" href="assets/countdown/jquery.countdown.css" />
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<!-- JavaScript includes -->
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script src="assets/countdown/jquery.countdown.js"></script>
<script src="assets/js/script.js" charset="UTF-8"></script>
<script>
$(function() {
$(".submit").click(function() {
var sposti = $("input#sposti").val();
if (sposti == "") {
alert ('Kirjoita nyt jotain herranjestas tuohon!');
return false;
}
var dataString = $('#formi').serialize();
//alert (dataString);return false;
$.ajax({
type: "POST",
url: "mailer.php",
data: dataString,
success: function() {
$("#thanks").slideDown('slow');
}
});
return false;
});
});
</script>
</head>
<body>
<div id="thanks" style="width:100%; height:100px; background:url('../img/page_bg_center.jpg') no-repeat center center;
position:absolute; top:0px; border-bottom:2px solid black; text-align:center; display:none;"><span style="position:absolute; top:30px;">Kiitos! Saat tiedon kun sivusto avautuu :)</span></div>
<div id="countdown"></div>
<p id="note"></p>
<p style="text-align:center; color:#666666; text-shadow: 2px 2px 0 rgba(255, 255, 255, 0.3);">Haluatko tiedon kun sivusto aukeaa? Anna sähköpostisi alle.<br><br></p>
<form action="#" method="post" style="text-align:center;" id="formi">
<input type="email" name="sposti"> <input type="submit" class="submit" style="width:50px;">
</form>
</body>
</html>