Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/415.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 需要修改此函数,该函数返回所有样式完整的任何DOM元素的代码_Javascript_Css - Fatal编程技术网

Javascript 需要修改此函数,该函数返回所有样式完整的任何DOM元素的代码

Javascript 需要修改此函数,该函数返回所有样式完整的任何DOM元素的代码,javascript,css,Javascript,Css,我在StackOverflow上发现了这个很棒的脚本,它返回所有样式完整的任何DOM元素的代码: 唯一的问题是,(看起来)它不会计算并返回原始元素的样式。它只对内部元素执行此操作。我如何修改它?这样它就返回完整的代码,以及原始元素的样式 (我无法对我的low rep的原始线程进行评论)递归调用的问题是它必须有和start和end case。不需要做很多工作,您就可以通过创建选定元素的父元素并使用它来实现这一点 /*grab the page*/ var orgin = $('body').htm

我在StackOverflow上发现了这个很棒的脚本,它返回所有样式完整的任何DOM元素的代码:

唯一的问题是,(看起来)它不会计算并返回原始元素的样式。它只对内部元素执行此操作。我如何修改它?这样它就返回完整的代码,以及原始元素的样式


(我无法对我的low rep的原始线程进行评论)

递归调用的问题是它必须有和start和end case。不需要做很多工作,您就可以通过创建选定元素的父元素并使用它来实现这一点

/*grab the page*/
var orgin = $('body').html();
/*grab the contents you are looking for, then replace the body*/
$('body').html($('widgets'));
/*get the widgets style*/
var htm = $('body')[0].serializeWithStyles();
/*give the body back to origin*/
$('body').html(orgin);
/*append the results*/
$('prepend').html($("<div>").text(htm).html())
/*抓取页面*/
var orgin=$('body').html();
/*抓取您要查找的内容,然后更换主体*/
$('body').html($('widgets'));
/*获取小部件样式*/
var htm=$('body')[0]。serializeWithStyles();
/*使身体回到原点*/
$('body').html(orgin);
/*附加结果*/
$('prepend').html($(“”).text(htm).html()


如果不需要body标记,您可以去掉它们,这是一个简单的解析。

递归调用的问题是它必须有and start和end case。不需要做很多工作,您就可以通过创建选定元素的父元素并使用它来实现这一点

/*grab the page*/
var orgin = $('body').html();
/*grab the contents you are looking for, then replace the body*/
$('body').html($('widgets'));
/*get the widgets style*/
var htm = $('body')[0].serializeWithStyles();
/*give the body back to origin*/
$('body').html(orgin);
/*append the results*/
$('prepend').html($("<div>").text(htm).html())
/*抓取页面*/
var orgin=$('body').html();
/*抓取您要查找的内容,然后更换主体*/
$('body').html($('widgets'));
/*获取小部件样式*/
var htm=$('body')[0]。serializeWithStyles();
/*使身体回到原点*/
$('body').html(orgin);
/*附加结果*/
$('prepend').html($(“”).text(htm).html()

如果不需要,可以去掉body标记,这是一个简单的解析