1 、 JavaScript 方法 : Document.getElementById ("id"). InnerHtml;
(1 )实例说明
复制代码代码如下:
<! Doctype html public "-// w3c // dtd xhtml 1.0 transisi // en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv = "konten tipe" content = "text /html; charset = utf-8" />
<title> 获取 html 中的子项 </iteme>
<type skrip = "Teks/JavaScript">
fungsi gettr ()
{
var str = document.getElementById ("Div_child"). InnerHtml;
waspada (str);
}
</script>
</head>
<body>
<Div id = "Div_child">
<able>
<tr>
<t th> </th>
<t th> </th>
<t th> </th>
<t th> </th>
<t th> </th>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</boable>
<input type = "tombol" id = "btn" ontClick = "getTtr ()" value = "获取字符串"/>
</div>
</body>
</html>
(2 )点击按钮后 , 弹出信息
2 、 jQuery 中的方法 : $ ("#id"). Html ()
(1 )实例说明
复制代码代码如下:
<! Doctype html public "-// w3c // dtd xhtml 1.0 transisi // en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv = "konten tipe" content = "text /html; charset = utf-8" />
<title> jQuery 中父节点获取子节点字符串 </title>
<script type = "text/javascript" src = "jQuery-2.1.0.js"> </script>
<type skrip = "Teks/JavaScript">
$ (function () {
$ ("#btn"). Klik (function () {
var str = $ ("#div_child"). html ();
waspada (str);
});
});
</script>
</head>
<body>
<Div id = "Div_child">
<able>
<tr>
<t th> </th>
<t th> </th>
<t th> </th>
<t th> </th>
<t th> </th>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</boable>
<input type = "tombol" id = "btn" value = "获取值"/>
</div>
</body>
</html>
(2 )运行结果