自定义 jQuery 横幅旋转器仅适用于 FireFox

发布于 2024-10-04 17:13:28 字数 1553 浏览 1 评论 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 属于AuctionsAuctions.Featured_TopBanner.Init(); 也在页面加载时运行。

干杯

I've wrote the following bit of jQuery for a banner rotator I have:

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);

    }
}

However, this code only works in FireFox.

Internet Explorer 8 returns an 'Invalid Argument' error with Line 116 of the jQuery javascript file.

It's worth noting, this is only a code-snippet, and Featured_TopBanner belongs to Auctions. Also Auctions.Featured_TopBanner.Init(); is ran at Page Load.

Cheers

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最丧也最甜 2024-10-11 17:13:28

尝试更改此设置(为了清晰起见,断行):

$(".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] + ")"
   );

请注意缺少的右括号。

Try changing this (lines broken for clarity):

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

To this:

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

Note the missing closing parenthesis.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文