以下验证码在所有MAC浏览器上均可100%运行。但是在所有PC浏览器上都会忽略验证。用户提交表单后,将验证电子邮件并返回一条感谢信息。有没有理由说它在PC浏览器上不起作用?
function validateModalForm(modalemail) {
var regexp = /^[\w-\.]{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,3}$/;
return regexp.test(modalemail);
}
$(document).ready(function() {
var clearMePrevious = "";
// clear input on focus
$("#modalemail").focus(function() {
if ($(this).val() == $(this).attr("title")) {
clearMePrevious = $(this).val();
$(this).val("");
}
});
// if field is empty afterward, add text again
$("#modalemail").blur(function() {
if ($(this).val() == "") {
$(this).val(clearMePrevious);
}
});
$('#submitmodalemail').click(function() {
if (!validateModalForm($(modalemail).val())) {
$("#modal_error").html("Invalid Email. Try again.");
return false;
}
app.ajax.load({
reqName: 'emailSubmit',
url: "$httpUrl('Bronto - OptIn')$?email=" + $('#modalemail').val(),
selector: '#modalemailbox',
callback: function(responseText, textStatus) {}
});
return false;
});
});
<form id="emailsignup_modal" name="emailsignup_modal" method="post" action="$httpUrl('Bronto-OptIn', 'fid', 'information')$">
<input class="email_field" type="text" title="Enter Your Email Address" value="Enter Your Email Address" name="email" id="modalemail" />
<button class="email-signup-btn" value="Submit" name="submitmodalemail" id="submitmodalemail"></button>
</form>
<div id="modal_error"></div>
<div class="privacy"><a href="Page-Show?cid=privacy-policy" target="_blank" title="Privacy Policy">Privacy Policy.</a> *Offer valid for first-time subscribers only.</div>
</div>
</div>