The parent node gets the string sample code for the child node
- 2020-03-30 02:09:10
- OfStack
1. JavaScript method: document.getelementbyid ("id"). InnerHTML;
(1) example illustration
(2) after clicking the button, the message pops up
< img SRC = "border = 0 / / files.jb51.net/file_images/article/201402/201402261631123.gif? 2014126163144 ">
2. Methods in jQuery: $("#id").html()
(1) example illustration
(2) operation results
< img SRC = "border = 0 / / files.jb51.net/file_images/article/201402/201402261632154.gif? 2014126163228 ">
(1) example illustration
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> To obtain HTML The children in </title>
<script type="text/javascript">
function getStr()
{
var str = document.getElementById("div_child").innerHTML;
alert(str);
}
</script>
</head>
<body>
<div id="div_child">
<table>
<tr>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
<input type="button" id="btn" onclick="getStr()" value=" Get string "/>
</div>
</body>
</html>
(2) after clicking the button, the message pops up
< img SRC = "border = 0 / / files.jb51.net/file_images/article/201402/201402261631123.gif? 2014126163144 ">
2. Methods in jQuery: $("#id").html()
(1) example illustration
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery The parent node gets the child node string </title>
<script type="text/javascript" src="jquery-2.1.0.js"></script>
<script type="text/javascript">
$(function(){
$("#btn").click(function(){
var str = $("#div_child").html();
alert(str);
});
});
</script>
</head>
<body>
<div id="div_child">
<table>
<tr>
<th></th>
<th></th>
<th></th>
<th></th>
<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>
</table>
<input type="button" id="btn" value=" Get the value "/>
</div>
</body>
</html>
(2) operation results
< img SRC = "border = 0 / / files.jb51.net/file_images/article/201402/201402261632154.gif? 2014126163228 ">