在下面的腳本中,我檢查輸入的電子郵件是否有效。這不是最好的正則表達式,但現在可以。此外,目前我不做任何服務器端檢查輸入。只有這個腳本。表單在jQuery中輸入無效時錯誤地顯示成功提醒框
我有這個問題,但:
當電子郵件是有效的,經過我鍵入了無效的電子郵件,我得到第一您的郵件地址格式無效然後我們何時推出,將會通知您。謝謝!警報。還發送電子郵件。如何解決這個問題?
謝謝
這是我的形式
<form id="myform" action="" method="POST">
<input id="subscribe" name="subscribe" class="subscribe floatLeft" type="text">
<button id="signUp" class="signUp floatRight" ><intro>notify!</intro></button>
<div class="clear"> </div>
</form>
,這裏是腳本
var signUp = function(inputEmail) {
var isValid = true;
var emailReg = /^([\w-\.][email protected]([\w-]+\.)+[\w-]{2,4})?$/;
if (!emailReg.test(inputEmail)) {
isValid = false;
alert('Your email is not in valid format');
}
$("#myform").submit(function(event) {
event.preventDefault();
if (!isValid) {
return false;
} else {
$.post('mailme.php', $("#myform").serialize(), function(data) {
alert('You will be notified when we launch. Thank you!');
});
return false;
}
});
};
這將有助於:http://stackoverflow.com/questions/7539752/how-to-refresh-only-a-part-of-the-page-when-f5-or-refresh-button-is -Pressed/7539830#7539830 –
@BookOfZeus但如何? – asotshia
@asotshia顯示你的HTML,你從哪裏調用'signUp'。 –