Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/379.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 如何将外部html文件作为DOM树读取?_Javascript_Html_Dom - Fatal编程技术网

Javascript 如何将外部html文件作为DOM树读取?

Javascript 如何将外部html文件作为DOM树读取?,javascript,html,dom,Javascript,Html,Dom,html文件很简单,如下所示 <table id="test"> <tr> <td>f1</td> <td>f2</td> </tr> <tr> <td>y</td> <td>70</td> </tr> </table> 选择一个文件 使用jqueryload方法 $('#someDivId').load('some-file

html文件很简单,如下所示

<table id="test">
<tr>
<td>f1</td>
<td>f2</td>
</tr>
<tr>
<td>y</td>
<td>70</td>
</tr>
</table>

选择一个文件

使用
jqueryload
方法

$('#someDivId').load('some-file.html');

使用
jqueryload
方法

$('#someDivId').load('some-file.html');

API的作用就是:

var标记=“”+
''+
“f1”+
‘f2’+
''+
''+
“是的”+
'70'+
''+
'';
var parsedDoc=new DOMParser().parseFromString(标记“text/html”);
log('行数:',parsedDoc.getElementById('test')。rows.length)
console.log('textContent of the third td:',parsedDoc.querySelectorAll('td')[3].textContent)API只做以下工作:

var标记=“”+
''+
“f1”+
‘f2’+
''+
''+
“是的”+
'70'+
''+
'';
var parsedDoc=new DOMParser().parseFromString(标记“text/html”);
log('行数:',parsedDoc.getElementById('test')。rows.length)

console.log('textContent of the third td:',parsedDoc.querySelectorAll('td')[3].textContent)
从用户文件中,首先需要使用FileReader将其编码为dataURI从用户文件中,首先需要使用FileReader将其编码为dataURI