这发生在IE和Firefox中。不在chrome中。
我有此形式:
<form id="enviaEmail" method="post">
<label for="nombre">Nombre</label>
<input id="nombre" type="text" name="nombre" required="" />
<label for="apellido">Apellido</label>
<input id="apellido" type="text" name="apellido" required="" />
<label for="email">E-mail</label>
<input id="email" type="email" name="email" required="" />
<label for="telefono">Teléfono</label>
<input id="telefono" type="text" name="telefono" />
<label for="mensaje">Comentarios</label>
<textarea id="mensaje" name="mensaje" required="" ></textarea>
<input id="submit" type="submit" name="submit" value="Enviar" />
</form>
和这个javascrpt附加我自己的活动,该活动以ajax为单位:
(function ($) {
$(document).ready(function () {
// ação que oculta a mensagem ao clicar no x
$(".close").on('click', function () {
$(this).parent().fadeOut();
})
// REQUISIÇÃO AJAX ENVIO DE E-MAIL
$("#enviaEmail").on("submit", function (event) {
event.preventDefault();
// pega todos inputs
var value = $(this).serializeArray(),
// objeto de dados para requisição
request = {
'option': 'com_ajax',
'module': 'wgajaxcontato',
'data': value,
'format': 'jsonp'
};
// requisição ajax
$.ajax({
type: 'POST',
data: request,
beforeSend: function () {
$('.hum_form_contact .formulario .loading').fadeIn().css('display', 'table');
$("#enviaEmail #submit").attr("disabled", true);
},
success: function (resposta) {
$("#resposta").fadeIn().html(resposta).delay(5000);
//$("#resposta").fadeIn().html(resposta).delay(5000).fadeOut(500);
},
complete: function () {
$(".hum_form_contact .formulario .loading").fadeOut().css('display', 'none');
$("#enviaEmail #submit").attr("disabled", false);
$("#nombre").val("");
$("#apellido").val("");
$("#email").val("");
$("#assunto").val("");
$("#telefono").val("");
$("#mensaje").val("");
$("#sccaptcha").val("");
}
});
});
});
})(jQuery);
问题在于,在Chrome中,所有这些都可以完美。也就是说,我填写表单,然后按"提交"按钮时,该表格使用我的自定义事件处理程序中的代码发送帖子。
在Firefox或IE中,按下提交按钮时,该表格将使用默认处理程序提交,因此整个页面都会重新加载。我可以意识到这一点,因为如果我在处理程序中放置警报,则不会显示。
这里有什么问题?
在控制台中没有显示错误,因此HTML或JavaScript中似乎没有错误。
谢谢Jaime
旧IE版本具有event.returnValue = false
尝试以IE和其他浏览器支持: event.preventDefault ? event.preventDefault() : event.returnValue = false;
IE旧事件属性