我已经编写了以下代码,但表单试图发布好像没有找到 javascript?
代码在<head>
文档中:
<script language="JavaScript" type="text/javascript">
$('.entrysend').click(function(e){
e.preventDefault();
var error = false;
var name = $('#name').val();
var address = $('#address').val();
var phone = $('#phone').val();
var email = $('#email').val();
if(name.length == 0){
var error = true;
alert("Please complete all fields");
}
if(address.length == 0){
var error = true;
alert("Please complete all fields");
}
if(phone.length == 0){
var error = true;
alert("Please complete all fields");
}
if(email.length == 0){
var error = true;
alert("Please complete all fields");
}
if(error == false){
$.post("compthanks.asp",
$(".entry").serialize(),
function(result){
if($.trim(result) == 'sent'){
$('.entrysend').remove();
alert("Thanks for entering!");
}
}
</script>
HTML:
<form class="entry" action="compthanks.asp" method="post" class="floatClear" name="entryForm">
<br class="floatClear" />
<div class="formwrapper">
<input name="name" id="name" type="text" placeholder="FullName" />
</div>
<div class="formwrapper">
<textarea name="address" id="address" placeholder="Address" cols="20" rows="10"></textarea>
</div>
<div class="formwrapper">
<input name="phone" id="phone" type="text" placeholder="ContactNumber" />
</div>
<div class="formwrapper">
<input name="email" id="email" type="text" placeholder="Email" />
</div>
<div class="formwrapper floatClear">
<input name="submit" type="submit" value="Send Entry" class="entrysend" />
</div>
</form>
谁能指出为什么表单仍然提交而不是 javascript 启动的原因?