<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <div id="temp"> <tr> <td>dad</td> </tr> <tr> <td>dad</td> </tr> </div> </body> <script> var divDom=document.getElementById("temp").innerHTML; console.log(divDom); </script> </html>
不管怎么整都获取不到tr,td,想了半天没有想明白,最后在tr上添加table,完整了一下结果,结果出来了,说明想要获取tr,td必须在正规的写法下,例如
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <div > <table id="temp"> <tr> <td>dad</td> </tr> <tr> <td>dad</td> </tr> </table> </div> </body> <script> var divDom=document.getElementById("temp").innerHTML; console.log(divDom); </script> </html>
这样就可以获取到tr,td.