Created
September 23, 2015 18:21
-
-
Save rc1021/7fb68065c220a9530a0c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
$(function () { | |
$("#user_success").on('submit', function(){ | |
var message = ""; | |
var emptyValue = false; | |
var name = $('[name="name"]', $(this)).val(); | |
var area = $('select[name="area"] option:selected', $(this)).val(); | |
var time = $('select[name="time"] option:selected', $(this)).val(); | |
var email = $('[name="email"]', $(this)).val(); | |
var phone = $('[name="phone"]', $(this)).val(); | |
if (area=='blank') { | |
alert('請選擇區域'); | |
return false; | |
}; | |
if (time=='blank') { | |
alert('請選擇時段'); | |
return false; | |
}; | |
if(name == "") | |
{ | |
message = "請輸入姓名\n"; | |
emptyValue = true; | |
} | |
if(email == "") | |
{ | |
message = message + "請輸入email\n"; | |
emptyValue = true; | |
} | |
else if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)) | |
{ | |
message = message + "email輸入格式錯誤\n"; | |
emptyValue = true; | |
} | |
if(phone == "") | |
{ | |
message = message + "請輸入電話\n"; | |
emptyValue = true; | |
} | |
else if(!/^[09]{2}[0-9]{8}$/.test(phone)) | |
{ | |
message = message + "手機號碼格式錯誤\n"; | |
emptyValue = true; | |
} | |
if(emptyValue) | |
{ | |
alert(message); | |
return false; | |
} | |
else | |
{ | |
var post_url = $(this).attr('action'); | |
$.ajax({ | |
type: "POST", | |
cache: false, | |
url: post_url, // preview.php | |
data: $("#user_success").serializeArray(), // all form fields | |
success: function (data) { | |
alert(data); | |
} | |
}); | |
document.getElementById("user_success").reset(); | |
} | |
return false; | |
}); | |
}); | |
</script> |
line: 55 ~ 65
就是為何送出表單不換頁的原因
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
如果有問題請直接在這裡留言.........謝謝