gpt4 book ai didi

javascript - Jquery/Ajax 表单在 IE7 上不工作

转载 作者:行者123 更新时间:2023-11-29 18:34:40 25 4
gpt4 key购买 nike

我在这个需要 jquery/ajax 联系表的网站上工作。除了 IE7(可能还有 IE6、8 甚至 9)之外,一切都很好,但没有要求/预期/不需要对它们的支持。这是现场版:

http://njutsu.net

无论如何,这是 JQuery 代码:

<!-- JS -->
<script type="text/javascript" src="scripts/jquery.js"></script>
<script>
function valid_email(email) {
if (!(/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i).test(email))
return false;

return true;
}


$(function(){
$("#testclass").submit(function(){


if (!valid_email($('#email').val())) {
alert('Por favor escribe un email valido.');
$('#email').focus();

return false;
}

if ($('#nombre').val().length == 0) {
alert('Por favor escribe tu nombre.');
$('#nombre').focus();

return false;
}

if ($('#apellido').val().length == 0) {
alert('Por favor escribe tu apellido.');
$('#apellido').focus();

return false;
}

if ($('#edad').val().length == 0) {
alert('Por favor escribe tu edad.');
$('#edad').focus();

return false;
}

if ($('#telcel').val().length == 0) {
alert('Por favor escribe tu telefono o celular.');
$('#telcel').focus();

return false;
}

if ($('#razon').val().length == 0) {
alert('Por favor escribe la razon por la cual deseas tomar una clase de prueba.');
$('#razon').focus();

return false;
}






$.ajax({url: "testclass.php",
datatype: 'html',
type:'POST',
data: { "email": $("input[type=text][name=email]").val(),
"nombre": $("input[type=text][name=nombre]").val(),
"apellido": $("input[type=text][name=apellido]").val(),
"edad": $("input[type=text][name=edad]").val(),
"telcel": $("input[type=text][name=telcel]").val(),
"razon": $("textarea#razon").val(),
},
success: function (response,textstatus){
$("#secondary div.col1-2").html("<h4 class='thanks'>Gracias por enviar tu solicitud, nos pondremos en contacto apenas leamos tu mensaje para acordar una fecha y hora para tu clase de prueba.</h4>");
$("#secondary div.col1-2").hide();
$("#secondary div.col1-2").fadeIn(2000);
}
});
return false;
});



});


</script>

这是表单的 HTML:

<form id="testclass" action="testclass.php" method="post">
<div class="row">
<label>Tu E-Mail</label>
<input id="email" name="email" class="text" type="text">
</div>
<div class="halfrow left">
<label>Tu Nombre</label>
<input id="nombre" name="nombre" class="text" type="text">
</div>
<div class="halfrow">
<label>Tu Apellido</label>
<input id="apellido" name="apellido" class="text" type="text">
</div>
<div class="halfrow left">
<label>Tu Edad</label>
<input id="edad" name="edad" class="text" type="text">
</div>
<div class="halfrow">
<label>Tu Teléfono o Celular</label>
<input id="telcel" name="telcel" class="text" type="text">
</div>
<div class="row">
<label>Razón por la cual deseas tomar clases de Ninjutsu Instintivo</label>
<textarea id="razon" name="razon" class="textarea" cols="" rows=""></textarea>
</div>
<div class="row">
<h5><input class="button" type="submit" value="Quiero tomar una clase de prueba" /></h5>
</div>
</form>

在任何情况下,如果表单的关键区域在提交时没有“填写”,则会有一个 PHP 检查将您带到/iefail.php 并让您知道。

我是 Jquery 的新手,因此除了了解 IE 系列浏览器(如果是互联网的耻辱)之外,我对 IE7 与 Jquery 不兼容问题背后的原因没有扎实的了解。感谢所有帮助。

附言我确实检查过,我在 IE7 上启用了 javascript,以防万一你想知道。

感谢所有帮助/指导

最佳答案

data 对象末尾的额外逗号导致 IE 严重失败:

data: { "email": $("input[type=text][name=email]").val(),
"nombre": $("input[type=text][name=nombre]").val(),
"apellido": $("input[type=text][name=apellido]").val(),
"edad": $("input[type=text][name=edad]").val(),
"telcel": $("input[type=text][name=telcel]").val(),
"razon": $("textarea#razon").val(), <-- here
},

关于javascript - Jquery/Ajax 表单在 IE7 上不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4417347/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com