我在一个网站上工作,它有一些jquery滑块,以及一些其他功能。然而,在IE中每跳转几个页面(就我所见的IE而言),jquery就不会加载,从而破坏页面。IE中有时无法加载的部分来自jquery.cycle.all.js文件。以下是我的代码的javascript部分。
<script type="text/javascript" src="javascript/modernizr.js"></script>
<script type="text/javascript" src="javascript/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="javascript/jquery.cycle.all.js"></script>
<script type="text/javascript">
$(document).ready(function() {
if (!Modernizr.input.placeholder) {
$('input[placeholder], textarea[placeholder]').each(function(index, elem) {
elem = $(elem);
placeholder = elem.attr('placeholder');
elem_id = elem.attr('id');
elem_name = elem.attr('name');
clone = elem.clone();
clone.hide();
if (elem_id) {
clone.attr({'id': elem_id+'-fake'});
}
if (elem_name) {
clone.attr({'name': elem_name+'-fake'});
}
clone.addClass('fake');
clone.data({'original': $(elem)});
clone.val(placeholder);
clone.focus(function(e) {
e.preventDefault();
$(this).hide();
$(this).data('original').show().focus();
});
elem.blur(function() {
if ($(this).val() == '') {
$(this).hide();
$(this).next().show();
}
});
elem.after(clone);
elem.blur();
});
}
$('#image-slider').cycle({
speed: 1000,
timeout: 1000
});
$('#text-slider').cycle({
speed: 1000,
timeout: 10000
});
$('#ad-1').cycle({
speed: 1000,
timeout: 1000
});
$('#ad-2').cycle({
speed: 1000,
timeout: 1000
});
$('#gallery-slider').cycle({
speed: 2000,
timeout: 2500
});
});
function PopupCenter(pageURL, title, w, h) {
var left = (screen.width/2)-(w/2);
var top = (screen.height/2)-(h/2);
var targetWin = window.open (pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
}
</script>据我所知,占位符和#图像滑块部分每次都可以工作。#text-slider、#ad-1和#ad-2仅在IE中出现零星故障。有没有人告诉我我错过了什么,我快把头发都扯出来了。可在此处http://memorysquare.com/testSite/找到指向该站点的链接
发布于 2012-11-24 04:18:50
当我在Chrome中打开你的示例页面时,我看到
周期终止;选择器
找到零个元素
也许你的问题不在于JS,而在于你的标记。也许你还没有关闭一些div或者定义了一组空的元素。此外,页面也不能在Chrome中工作。
编辑:是的,我认为问题出在你的标记上。在你的FAQ页面上,IE简单地中断,但在你的页脚中显示了4张图片,但Chorme没有显示任何东西。如果我转到Chrome开发人员工具,我会看到它在你的页脚中激活了一些元素。
发布于 2012-11-24 04:42:47
看一看这个例子,并尽量不去责怪Internet Explorer,我可以为你提出一些建议。
首先,我认为你遇到的问题不是在jQuery或IE中(尽管大多数问题都是在IE中),而是在你的“周期”插件中。如果你的目标是旋转木马效果,我建议你看看推特的Bootstrap @ http://twitter.github.com/bootstrap
在那里,您将发现一组令人惊叹的样式和脚本,它们将允许您使用基本标记来设置滑块。下面是一个使用Bootstrap的示例。
标记看起来就像这样:
<!-- The carousel container -->
<div id="slider" class="carousel slide">
<!-- The carousel -->
<div class="carousel-inner">
<div class="active item">
<!-- Here you can put the image itself, as well as a custom element to hold a caption -->
<img src="/path/to/image.png" alt="Image Not Found" title="Bootstrap Rocks!" />
<div class="carousel-caption">
<h4>The Title</h4>
<p>Some text.</p>
</div>
</div>
<div class="active item">
<img src="/path/to/image.png" alt="Image Not Found" title="Bootstrap Rocks!" />
</div>
<div class="active item">
<img src="/path/to/image.png" alt="Image Not Found" title="Bootstrap Rocks!" />
</div>
</div>
<!-- The anchors to move through the carousel -->
<a class="carousel-control left" href="#slider" data-slide="prev">‹</a>
<a class="carousel-control right" href="#slider" data-slide="next">›</a>
</div>最好的部分是,你不需要为它编写任何脚本。你可以按原样使用它,只是标记会自动初始化。
小贴士。
我只是觉得我应该给你一些技巧,因为你的目标是使你的网站支持internet explorer。
要使站点能够运行,即使Internet Explorer的所有东西都很糟糕,最好使用一些小工具和工具来为您优化站点。你不再需要做切换/案例来优化你的站点。
当您使用HTML5元素时,请尝试包含'HTML5Shiv @ http://code.google.com/p/html5shiv/‘。而对于CSS3,我写了'CSS3Shiv @ http://github.com/karimsa/css3shiv',但这要到一月份才能发布。
无论如何,浏览一下并检查你正在使用的插件是否能够自我优化是一个好主意,如果不能,我真的建议你寻找其他的插件。
https://stackoverflow.com/questions/13535209
复制相似问题