0

我正在使用 jQuery 1.7.2

此行在 IE9、Chrome 和 Firefox 上运行良好:

$('.' + product.id + '#' + this).text("foo");

product.id是表示类this的字符串,也是表示 id 的字符串。

该行位于 $.each 循环内,我没有发布此函数的整个代码,因为它相当大,并且错误恰好位于该行上。

使用此循环动态创建的选择器示例如下:

$('.price#servicesPerMonth').text("foo");

在 IE8 中,我收到以下错误:

Unexpected call to method or property access.  
jquery-1.7.2.js, line 5847 character 5

jQuery中的代码是这样的:

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

第 5847 行是this.appendChild( elem );

我认为问题来自连接thisjQuery 选择器中的变量,但我真的不知道解决此问题的替代方法。

有什么建议么?

4

1 回答 1

1

尝试使用

('.' + product.id + ' #' + this.id).text("foo");

或者

('.' + product.id + ' #' + this.attr('id')).text("foo");

没关系,注意#前面的空格

于 2012-07-03T21:29:37.580 回答