我想最终遍历正文中的所有节点(尚未实现)并从每个节点获取背景和文本颜色。但是,我得到了Uncaught TypeError: Object #<HTMLBodyElement> has no method 'css'
。它发生在var bg = node.css("background-color");
这是我的代码
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();