0

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

4 回答 4

3

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

jQuery('#list script').appendTo('body');
于 2011-08-09T21:24:27.807 回答
1

你为什么不一直使用jquery?

jQuery('#list script').each(function() {
    jQuery('<script></script>')
        .attr('type','text/javascript')
        .text(jQuery(this).text())
        .appendTo(jQuery('body'));
}).remove();
于 2011-08-09T21:24:16.437 回答
1

更多地使用jquery怎么样......

jQuery('#list script').each(function() {
    jQuery('<script type="text/javascript" />').text(jQuery(this).text()).appendTo(jQuery('body'));
}).remove();
于 2011-08-09T21:22:27.453 回答
0

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

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

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

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

我建议一些更简洁的东西:

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

请注意,假设您使用的是 html5,我省略了类型,如果不是,您可以选择将其放在那里

于 2011-08-09T21:26:30.357 回答