每次 jQuery 选项卡 UI 中发生选项卡更改时,我都会使用下面的函数在 #quotescontainer 中显示随机引号。除了 IE7-8(当然)之外,在所有环境中都可以正常工作。
IE7-8 中发生的情况是显示第一个引号,然后第二个随机引号出现在第一个引号正下方的 #quotescontainer 中。在所有其他浏览器中,仅显示一个引号,并且它会在选项卡更改时旋转。因此,IE 会从 Quotes.html 中获取 div.quote 中的第一个引号,将其显示出来,并在第一个引号下面显示一个随机引号。
我可以尝试什么来强制 IE 正确交换引号?并且不会被第一句话“卡住”?
这是缓存问题吗?或者函数总是读取 quote1 并在其下方附加 quote2 的问题?
我没有在 .htaccess 中使用缓存。我尝试添加 $.ajaxSetup({cache: false});
在函数中没有运气。
2011 年 6 月 1 日修复; 问题是 <div class="quote">quote text</div>
内的一些 html在quotes.html 中。不知何故,这破坏了 IE7-8。
jsfiddle: http://jsfiddle.net/YAEe5/28/
我的职能: 在下面 Matthew Ratzloff 的帮助下
select: function(event, ui) {
var random = Math.floor(Math.random() * (Math.pow(2, 32) - 1));
$('div#quotescontainer').load('http://mydomain.com/quotes.html?' + random, function() {
var quotes = $(this).find('div.quote');
var index = Math.floor(Math.random() * quotes.length);
quotes.hide().eq(index).fadeIn();
});
引号显示在 #quotescontainer
的页面上
quotes.html 包含以下内容:
<div class="quote">Quote1</div>
<div class="quote">Quote2</div>
<div class="quote">Quote3</div>
最佳答案
这是一个完整的、经过测试的、可行的示例,说明了您想要做的事情。您应该能够将 $(document).ready
函数内的所有内容提取到您的 select
处理程序中。
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script>
</head>
<script>
$(document).ready(function() {
var random = Math.floor(Math.random() * (Math.pow(2, 32) - 1));
$('div#quotescontainer').load('quotes.html?' + random, function() {
var quotes = $(this).find('div.quote');
var index = Math.floor(Math.random() * quotes.length);
quotes.hide().eq(index).fadeIn();
});
});
</script>
<div id="quotescontainer"></div>
</html>
关于jquery - 如何阻止 IE7-8 缓存此 jQuery 函数的显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5994928/