【问题标题】:jquery working in FF, chrome, and safari but not IEjquery 在 FF、chrome 和 safari 中工作,但不适用于 IE
【发布时间】:2016-12-13 02:06:04
【问题描述】:

您好,我无法在 Internet Explorer 中使用以下 jquery 脚本。更多按钮没有响应。我找不到任何小的语法错误等。有人可以帮我更改脚本,以便它可以在 IE 上运行。如果我在兼容模式下运行 IE,它就可以工作。谢谢。

$(document).ready(function() {
    var pid = $("div#productcontainerbottom").attr("class");
    var initialtotalcomments = $(".loadmore").attr("id"); //total comments before any inserts or deletes
    initialtotalcomments = parseInt(initialtotalcomments);
    if (initialtotalcomments <= 10) {
        $(".loadmore").hide();
    }
    if (initialtotalcomments >= 11) {
        $(".loadmore").show();
        $("#commentview").html(10 + " of ");
        $("#commentcount").html(initialtotalcomments);
    }
    $(".loadmore").click(function(e) {
        e.preventDefault();

        $.post("ajax/commentcount.php?id=" + pid, function(actualtotalcount) {
            var commentviewcountbeforeclick = $('.date').length; //number of comments displayed on page before more click. varies due to inserts or deletes before click of more button. each insert increases it by 1. each delete decreases it by 1.
            actualtotalcount = parseInt(actualtotalcount);
            //keeps track of actual total comment count adjusted for inserts and deletes
            var end = commentviewcountbeforeclick + 10;
            $(".loading").show();
            $.post("ajax/pull.php?id=" + pid, {
                end: end
            }, function(data) {
                $("#commentarea").html(data);
                $('.confirmdelete').hide();
                $(".loading").hide("slow");
                var commentviewafterclick = $('.date').length; //number of comments displayed on page after click(= to commentviewbeforeclick + num)
                if (actualtotalcount >= 11) {
                    $("#commentview").html(commentviewafterclick + " of ");
                    $("#commentcount").html(actualtotalcount);
                }
                if (commentviewafterclick == actualtotalcount) {
                    $(".loadmore").hide();
                }
            });
        });
    });
});

【问题讨论】:

  • “我无法让下面的 jquery 脚本在 Internet Explorer 中运行” 这没什么好说的!
  • 更多按钮没有响应
  • 您是否在 JavaScript 控制台中看到错误?
  • @Juhana 当我单击加载更多时,错误控制台产生以下 SCRIPT65535:无效调用对象 jquery.js,第 3 行字符 31871

标签: jquery internet-explorer cross-browser incompatibility


【解决方案1】:

第 38 行和第 40 行,添加 ;。您还应该在parseInts 中指定radix 参数。尝试这样做,也许 IE 会正常运行。

编辑:您还不止一次初始化actualtotalcount

【讨论】:

  • 对不起,我重新格式化了代码,所以你的行号可能是关闭的。基本上,他们在$.post() 调用之后需要;
  • 我做了除了基数参数之外的所有更改...仍然需要查找那是什么。还是不行。 javascript 控制台产生以下错误 SCRIPT65535: Invalid calling object jquery.js, line 3 character 31871
【解决方案2】:

不要复活一个相当死的帖子,但我遇到了同样的错误。我遇到的问题是我传递的帖子参数中有一个对象(在我的例子中是一个location 对象)。切换到字符串 URL 解决了这个问题。

如果您将一个空对象传递给$.post()$.getJSON() 调用并且没有收到错误,请查看您传入的参数。

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-09
    • 1970-01-01
    • 2015-08-11
    • 2023-04-05
    • 1970-01-01
    • 1970-01-01
    • 2010-12-01
    • 1970-01-01
    相关资源
    最近更新 更多