jQuery IE8问题

时间:2011-08-09 21:12:33

标签: jquery appendchild

IE8在第4行抛出错误。

jQuery('#list script').each(function() {

    var script=document.createElement('script');
    script.type='text/javascript';
    jQuery(script).text(jQuery(this).text()); //Error in IE8  does the field editing
    document.body.appendChild(script);
}).remove();

例程中的jquery错误:

append: function() {
    return this.domManip(arguments, true, function( elem ) {
        if ( this.nodeType === 1 ) {
            this.appendChild( elem );
        }
    });

4 个答案:

答案 0 :(得分:3)

您不必重新创建脚本元素或执行所有显式删除操作。您可以简单地执行以下操作:

jQuery('#list script').appendTo('body');

答案 1 :(得分:1)

如何更多地使用jquery ......

jQuery('#list script').each(function() {
    jQuery('<script type="text/javascript" />').text(jQuery(this).text()).appendTo(jQuery('body'));
}).remove();

答案 2 :(得分:1)

为什么不一直使用jquery?

jQuery('#list script').each(function() {
    jQuery('<script></script>')
        .attr('type','text/javascript')
        .text(jQuery(this).text())
        .appendTo(jQuery('body'));
}).remove();

答案 3 :(得分:0)

猜测这是一个安全例外,因为你没有列出任何内容。

虽然没有问题解释确切的行(在jquery例程中)和确切的异常,但这只是在黑暗中刺伤。

可能是您正在访问页面域外的脚本,因此不允许您访问其文本。

它也可能是您创建脚本标记的方式。

我建议更简洁一些:

$('#list script').each(function() {
    $('<script>').text($(this).text()).appendTo($(document.body));
})
.remove();

注意我假设您使用的是html5时遗漏了类型,如果没有,您可以选择将其放在那里