上我目前有此:我如何通过每一个HTML元素遍历网页
$(document).ready(function() {
$(this).each(function(index) {
delete style;
var style = $(this).attr("style");
document.write(style);
));
});
但是这不工作:/只是不断告诉我style
是不确定的。不太确定该从哪里出发。
谢谢。
上我目前有此:我如何通过每一个HTML元素遍历网页
$(document).ready(function() {
$(this).each(function(index) {
delete style;
var style = $(this).attr("style");
document.write(style);
));
});
但是这不工作:/只是不断告诉我style
是不确定的。不太确定该从哪里出发。
谢谢。
$('*').each(function() {
var style = $(this).attr("style");
document.write(style); // better replace to console.debug(style); with Firebug installed
})
编辑:您当然不需要delete style
语句,这是错误源。
在什么浏览器上对未定义的变量“删除”会导致错误?我不认为这是OP想要的,因为载入后的'document.write'清除了现有的页面。 – 2011-04-04 20:41:03
对,代码看起来像是为实验写的,在这种情况下,我会使用'console.debug'而不是'document.write'。浏览器是IE – zindel 2011-04-04 20:50:10
$('*').each(function() {
document.write(this.style);
//or console.log(this.style)
});
FYI this.style指元素的样式对象。 $(本).attr(“风格”)将拉动元素的内嵌样式
它会告诉你,因为当你做delete style;
,变量风格尚未定义的样式是不确定的。
可以使用$('*')
迭代通过你的元素,你已经做的方式选择的一切,它的罚款。你究竟想用删除来做什么?
$('*').each(function() {
var style = $(this).attr("style");
document.write(style);
});
$(document).find('*').each(function()
{
$(this).removeAttr('style');
});
我甚至不知道上面会在所有的工作,但要确保你和声明或定义变量,您尝试使用它们之前。 IE:在'var style = ...'之后移动'delete style'只是你知道,delete是用于数组和对象的。 – Shaz 2011-04-04 20:36:28