一千萬個為什麽

搜索

在IE中不起作用

這是我的javasript:

            function random_imglink() {
            var myimages = [
                {image: "/documents/templates/projedepo/banner/canon.jpg", url: "/index.cfm?fuseaction=objects2.detail_product&product_id=612&stock_id=612"},
                {image: "/documents/templates/projedepo/banner/indigovision.jpg", url: "http://www.url2.com"}
            ];

            var ry=Math.floor(Math.random()*myimages.length);

            var randomImage = myimages[ry];

            var randomImageLink = '';
            document.getElementById("image2").innerHTML = randomImageLink;
            }
 $(function() {
  $(".image2").click(function() {
  var image = $(this).attr("rel");
    var rel = $('#random_img').hide().fadeIn('slow').attr('src');
    $('#random_img').attr('src', image);

  var randomLink = $(this).attr("href");
  $('#random_link').attr('href',randomLink);

    var image2 = $('#random_img').attr('src');
    $("#thumb2 a img").removeClass("open");
    $("#thumb2 a[rel='" + image2 + "'] img").addClass("open");
    return false;
  });
 }); 

 $(document).ready(function() {
   var image2 = $('#random_img').attr('src');
   $("#thumb2 a[rel='" + image2 + "'] img").addClass("open");
 });
                random_imglink()

這是我的HTML:

<div id="slider_container">    
<div id="image2">Here is written my sript</div>
<div id="thumb2">




</div></div>

IN Internet Explorer, NOT in Firefox or Opera, at first it works fine, the random image is displayed and thumbnails are ok, but when i click the thumbnail, the random image turns in frame with overflows, like this: http://vteam.net.ru/_fr/11/1923928.jpg

最佳答案

我看到的唯一可疑的是:

$(document).ready(function() {
   var image2 = $('#random_img').attr('src');
   $("#thumb2 a[rel='" + image2 + "'] img").addClass("open");
 });
                random_imglink()

在您編寫的HTML源代碼中

    <div id="image2">Here is written my sript</div>

...所以我假設腳本放在那裏。這可能是一個問題。用上面的代碼替換

$(document).ready(function() {
       var image2 = $('#random_img').attr('src');
       $("#thumb2 a[rel='" + image2 + "'] img").addClass("open");
       random_imglink();
     });

(將random_imglink()的調用移到ready-function中)。否則會立即調用,但會有一個元素被操作(#image2)尚未關閉,可能導致MSIE出錯。

轉載註明原文: 在IE中不起作用