我想依据 html 字符串动态的创建 document 对象,然后使用 getElementById 等方法获取我想要的内容。
例如,我想从下面的字符串中提取 div1 的 内容:
======================================
<!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>
<title>
无标题页
</title>
</head>
<body>
<form name= "form1 " method= "post " action= "GridView.aspx " id= "form1 ">
<div>
<input type= "hidden " name= "__VIEWSTATE " id= "__VIEWSTATE " value= "/wEPDwUJNjc2NTE4NTMzZBgBBQlHcmlkVmlldzEPZ2TtAKr8y11Z/GJxY3ofctOiabi30g== " />
</div>
<div id= "div1 ">
<table cellspacing= "0 " rules= "all " border= "1 " id= "GridView1 " style= "border-collapse:collapse; ">
<tr>
<th scope= "col "> UserId </th>
<th scope= "col "> UserPwd </th>
</tr>
<tr>
<td> user1 </td> <td> pwd1 </td>
</tr>
<tr>
<td> user2 </td> <td> pwd2 </td>
</tr>
</table>
</div>
</form>
</body>
</html>
------解决方案--------------------------------------------------------
alert(document.all.div1.innerHTML);
------解决方案--------------------------------------------------------
getElementById ( "div1 ").innerHTML
------解决方案--------------------------------------------------------
<script>
function a()
{
var a=document.getElementById( 'div1 ').innerHTML;
alert(a);
}
</script>