1
我想最終遍歷所有節點內的節點(尚未實現),並從每個節點獲取背景和文本顏色。但是,我得到Uncaught TypeError: Object #<HTMLBodyElement> has no method 'css'
。它是在var bg = node.css("background-color");
Uncaught TypeError:Object#<HTMLBodyElement> has no method'css'
存在的下面是我的代碼
function grabColors() {
var colorArray = new Array();
var body = $("body");
console.log(body);
body.each(function(index, node){
console.log(node);
getColorsFromChild(node);
});
console.log(colorArray);
}
function getColorsFromChild(node) {
var bg = node.css("background-color");
var bg2 = node.css("background");
var color = node.css("color");
if ($.inArray(bg, colorArray) == -1) {
colorArray.push(bg);
}
if ($.inArray(bg2, colorArray) == -1) {
colorArray.push(bg2);
}
if ($.inArray(color, colorArray) == -1) {
colorArray.push(color);
}
}
grabColors();