JQuery脚本,适用于Firefox,而不是在IE, Chrome

JQuery Script, Works in Firefox, not in IE, Chrome

本文关键字:IE Chrome 脚本 适用于 Firefox JQuery      更新时间:2023-09-26

我有下面的脚本,滑动一个容器向下和另一个向上,反之亦然,这取决于关闭/启用变量的条件。

该脚本在firefox中工作良好,但在IE和Chrome中,它只是不工作:(

谁能给点建议?

多谢!脚本如下:

(OCH变量接受通过ajax加载元素的容器的高度,因此它知道何时再次打开它打开多少px -这是最好的方式吗?)

            $(document).ready(function()
            {
                //Grab the height of the container after its loaded with all the calls in...
                var och = $('#calls').height();
                //Are we allowed to close this panel yet?
                var enabled = false;
                //is the panel closed or not?
                var closed = false;
                $(".survey-description").click(function () {
                    if (enabled == true) {
                        if (closed == false) {
                            $(this).closest("#calls").stop().animate({"height": "44px"}, "fast");
                            closed = true;
                        }
                        else {
                            $(this).closest("#calls").stop().animate({"height": och}, "medium");
                            closed = false;
                        }
                    }
                });
                $(".linktoCall").click(function () {
                    if (closed == false) {
                        //Now we can toggle the top panel...
                        enabled = true;
                        $(this).closest("#calls").stop().animate({"height": "44px"}, "fast");
                        closed = true;
                    }
                });
            });

编辑这里是渲染元素的一些html。

<div id="survey-description"></div>
<div id="calls">
    <div>
        <p onclick="showCall('tgkn5xabgnivkaf');" id="notstarted" class="linktoCall">59677 tgkn5xabgnivkaf<br>NOT STARTED - SAVED</p>
    </div>
</div>
<div id="aCall">
</div>

看一下HTML片段,我猜应该是

<div class="survey-description"></div>

,因为选择器$('.survey-description')指向的是一个类,而不是一个id。

这主要是一个快速的猜测,因为我不知道问题中的html结构,也没有时间检查其余的,但是如果有冲突的元素id(例如两个id为"calls"的元素),不同的浏览器将表现不同。检查一下,确保这不是问题。

(另外,在比较中使用===而不是==)

如果你的HTML代码无效,它可能无法工作…我敢打赌你没有关闭div之类的…

你可以在这里查看你的页面:http://validator.w3.org/

还请删除测试

中的"px"值
animate({"height": "xxpx"} ...

让它

animate({"height": 25}...