我正在为我的站点使用 jQuery 和 twitter bootstrap。我正在使用滚动 spy 、轮播和 AJAX 表单提交。我已经在三个浏览器中测试了这些。他们在 chrome 和 FF 中工作,但在 Internet Explorer 中不工作。
我是这些技术的新手,所以我可能错过了一些重要的兼容性问题 以下是我使用的脚本。
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script src="js/bootstrap.js"></script>
<script src="js/parsley.js"></script>
<!-- script to make the navigation scroll -->
<script>
var $root = $('html, body');
$('#nav a').click(function() {
var href = $.attr(this, 'href');
$root.animate({
scrollTop: $(href).offset().top
}, 500, function () {
window.location.hash = href;
});
return false;
});
</script>
<script>
// AJAX submit
$("#emailForm").submit(function() {
var url = "email.php";
$.ajax({
type: "POST",
url: url,
data: $("#emailForm").serialize(),
success: function(data)
{
$('#emailForm')[0].reset();
$('#contactForm').prepend('<h1 class="text-success" id="messageSent">Message sent!</h1>');
$("#messageSent").fadeIn("slow");
window.location.href = '#contact';
}
});
return false; // avoid to execute the actual submit of the form.
});
</script>
<!-- script to make the carousel work -->
<script>
// carousel demo
$('#myCarousel').carousel();
</script>
有人能指出/解释我方法中的错误吗
编辑:我正在使用 IE 8 对此进行测试。
最佳答案
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
您正在使用 2.0.0 版的 jQuery,它在 IE 8 中不起作用。您可以阅读此 here .
我建议您使用与较低 IE 版本兼容的 jQuery 版本,例如 1.9.1:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
关于JavaScript 与 IE8 的不兼容问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16498128/