0

私が持っているバナーローテーター用に、次のjQueryを少し書きました。

Featured_TopBanner: {
    Init: function () {
        var featItems
        $.ajax({
            url: '/Auctions/Auctions.asmx/Featured_TopBanner_Items'
          , type: 'POST'
          , contentType: 'application/json; charset=utf-8'
          , dataType: 'json'
          , success: function (data) {
              Auctions.Featured_TopBanner.ChangeSlide(data.d);
          }
        });
    },
    ChangeSlide: function (featItems) {

        var currentIndex = $(".auction_featured_top_currentindex").html();
        var newIndex = parseInt(currentIndex) + 1;

        if (newIndex > (parseInt(featItems.length) - 1)) {
            newIndex = 0;
        }1

        var featItem = featItems[newIndex];

        $(".auction_featured_top").fadeOut('slow', function () {
            $(".auction_featured_top_img").css("background-image", "url(/Auctions/ItemImg_TopBanner.ashx?itemid=" + featItem[0]);
            $(".auction_featured_top_link").attr("href", "/Auction/" + featItem[2] + ".aspx");
            $(this).fadeIn('slow');
        });

        $(".auction_featured_top_currentindex").html(newIndex);

        setTimeout(function () {
            Auctions.Featured_TopBanner.ChangeSlide(featItems);
        }, 15000);

    }
}

ただし、このコードは FireFox でのみ機能します。

Internet Explorer 8 は、jQuery JavaScript ファイルの 116 行目で「無効な引数」エラーを返します。

注目に値するのは、これは単なるコード スニペットであり、にFeatured_TopBanner属していることAuctionsです。Auctions.Featured_TopBanner.Init();ページ読み込み時にも実行されます。

乾杯

4

1 に答える 1

1

これを変更してみてください(わかりやすくするために線が壊れています)。

$(".auction_featured_top_img")
  .css(
      "background-image", 
      "url(/Auctions/ItemImg_TopBanner.ashx?itemid=" + featItem[0]
   );

これに:

$(".auction_featured_top_img")
  .css(
      "background-image", 
      "url(/Auctions/ItemImg_TopBanner.ashx?itemid=" + featItem[0] + ")"
   );

閉じ括弧がないことに注意してください。

于 2010-11-23T15:37:44.020 に答える