【问题标题】:jQuery. Prepend with fadeIn (error)jQuery。前置淡入(错误)
【发布时间】:2011-08-12 16:05:03
【问题描述】:

我使用了这里的代码jquery prepend + fadeIn

没有fadeIn 它可以工作

function updateResult(data) {
$('#test').prepend(
    html
);
}

fadeIn 仅在数据包含一个div 标签时有效,

$('#test').prepend(
    $(html).hide().fadeIn('slow')
);

否则 FireFox 会返回错误

uncaught exception: [Exception... "Could not convert JavaScript argument arg 0 [nsIDOMViewCSS.getComputedStyle]" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)" location: "JS frame :: http://code.jquery.com/jquery-latest.min.js :: <TOP_LEVEL> :: line 16" data: no]

如何重写这段代码?

更新。 在我的情况下,我已经通过这种方式解决了

data = data.replace(/(?:(?:\r\n|\r|\n)\s*)/gi, '');
$(data).hide().prependTo('#test').fadeIn('slow');

删除换行符后正常工作

【问题讨论】:

    标签: jquery


    【解决方案1】:

    试试这个:

    $(html).hide().prependTo('#test').fadeIn('slow');
    

    当元素未添加到 DOM 时,您可能无法使用动画方法。

    【讨论】:

    • @Tuco:那是另外一回事,因为它适用于我的 Firefox:jsfiddle.net/fkling/duM7a 你也可以尝试更改调用的顺序:$(html).prependTo('#test').hide().fadeIn('slow'); 虽然这可能会导致闪烁。
    • 也许它是 CSS 的东西,因为你的代码不使用它,我的使用它并且错误地有 nsIDOMViewCSS.getComputedStyle
    【解决方案2】:

    在 Firefox 和 Chrome 中测试此代码。我没有用 AJAX 测试过:

    HTML

    <div id="be-images">
        <ul>
            <li>lista</li>
        </ul>
    </div>
    <button type="button">button</button>
    

    JQUERY

    $('button').click(function(){
    $('#be-images ul').prepend(
        $('<p>response</p>').hide().fadeIn(2000)
    );
    });
    

    【讨论】:

      【解决方案3】:

      问题似乎在于换行符

      读完这个话题Common sources of unterminated string literal 我得到了一个后盾。服务器返回 html 代码,其中每个标签位于新行上,因此当 \n 和标签之间的空格被删除时,此错误消失了。

      这里是一个例子http://jsfiddle.net/gMWFD/

      【讨论】:

        猜你喜欢
        • 2010-12-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-09-07
        • 1970-01-01
        • 1970-01-01
        • 2012-12-22
        • 2023-03-27
        相关资源
        最近更新 更多