jquery - 如何阻止 IE7-8 缓存此 jQuery 函数的显示?

标签 jquery internet-explorer

每次 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/

相关文章:

html - Microsoft 是否有 HTML5 服务器发送事件的等效项?

css - @font-face EOT 不通过 HTTPS 加载

javascript - 在 IE8 中替换大下拉列表的最快方法

javascript - 具有相同类的 anchor 标记在 jquery 中单击按钮时不返回值

javascript - JQuery Ajax : Random order of dynamic div elements

javascript - jQuery - 根据输入链接中粘贴的链接选择一个选项

javascript - 更改 child 的 html

java - 无法访问 MS CRM 365 上的元素

jquery - 使用 jQuery 扩大和缩小 div

css - 选择元素上的IE6/IE7 CSS边框