我有一點jquery,提交一個電子郵件註冊表格爲我。當用戶點擊按鈕時,一切正常,但當命中輸入似乎表單試圖通過HTML提交,而不是通過jquery,你會發現表單應該發佈的位置。我一直在使用.submit代替。點擊試過但沒有似乎工作提交表單使用jquery,按鈕的作品,但不是'輸入'按
$('#email-signup-button').click(function() {
var email = $('#email-address').val();
// Check to see if field is blank
if (email.length < 1) {
errorLog += ('Please provide an email address.');
errorCount++;
}
// If field is email address, check w/ regex
if (email.match(emailRegex) == null) {
if (errorCount == 0) {
errorLog += ('Email address is invalid.\nPlease verify.');
errorCount++;
}
}
if (errorCount > 0) {
alert(errorLog);
errorCount = 0;
errorLog = "";
}
else {
$.post("/Home/AddEmail", { emailAddress: email });
alert('Thank you for signing up!');
$('#email-address').val("");
$('#email-signup').hide();
$('.lb_overlay').hide();
}
return false;
});
}
<div id="email-signup">
<h2>
Content Phrase
</h2>
<div class="email-deals-close-button">
</div>
<p>
More Content</p>
<form action="/Home/AddEmail" class="clearfix" method="post">
<p class="sign-up">
<label class="placeholder" for="email-address">
[email protected]</label>
<input type="text" id="email-address" name="email-address" value="" />
</p>
<button id="email-signup-button" type="button" class="green-action-button">
Submit</button>
</form>
</div>
id =「email-signup-button」,是的,這是我的電子郵件註冊按鈕 – Lawrence 2011-04-19 17:08:26
@勞倫斯 - 但它是'?看起來不是,那將意味着'.submit()'不能按預期工作。如果你不想使用提交按鈕,那麼我提供的窗口輸入修復程序將工作。 – justkt 2011-04-19 17:09:29
@ input type =「text」id =「email-address」name =「email-address」value =「」/>是他們輸入電子郵件的輸入 – Lawrence 2011-04-19 17:11:26