Jquery 无法读取foreach中的属性?

Jquery 无法读取foreach中的属性?,jquery,Jquery,我正试图删除一些div的style属性,但我无法这样做,当我将style属性记录到控制台日志中时,我将无法定义它 var divs = $('#addDescription').parent().children('div'); divs.each(function (i) { //console.log("wid", $(i).css("width")) console.log( $(i).attr("style")

我正试图删除一些div的style属性,但我无法这样做,当我将style属性记录到控制台日志中时,我将无法定义它

var divs = $('#addDescription').parent().children('div');
        divs.each(function (i)
        {
            //console.log("wid", $(i).css("width"))
           console.log( $(i).attr("style"))
            $(i).removeAttr("style");

        });

为什么我无法使用foreach读取style属性?

使用
this
代替
var I
i
是索引,是选择的第n项(例如0,1,2,3等)。 jQuery为您提供了一个
this
,它指的是每个元素的一个元素

var divs = $('#addDescription').parent().children('div');
divs.each(function (i){
    //console.log("wid", $(i).css("width"))
    console.log( $(this).attr("style"))
    $(this).removeAttr("style");
});

使用
this
代替
var i
i
是索引,是选择的第n项(例如0,1,2,3等)。 jQuery为您提供了一个
this
,它指的是每个元素的一个元素

var divs = $('#addDescription').parent().children('div');
divs.each(function (i){
    //console.log("wid", $(i).css("width"))
    console.log( $(this).attr("style"))
    $(this).removeAttr("style");
});

您没有使用正确的回调参数,
each(函数(索引,元素)
然后使用
element
$(元素)。attr(“style”)
您没有使用正确的回调参数,
each(函数(索引,元素)
然后使用
element
$(元素)。attr(“style”)
清理代码,并为您花费一点答案:)也尽量(合理地)解释。啊..好的@Martijn.谢谢清理代码,并为您花费一点答案:)也尽量(合理地)解释。啊。。好的,玛蒂恩。谢谢