如何使用JS获取父容器
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">http://www.w3.org/1999/xhtml"> function test() { var obj = document.getElementById("nation").parentNode;/
<!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>
<script type="text/javascript">
function test() {
var obj = document.getElementById("nation").parentNode;//获取父容器
var e = createEle();
obj.appendChild(e);
}
function createEle() {
var e = document.createElement("span");
e.innerHTML = "test";
return e
}
</script>
</head>
<body>
<form action="#" method="post" id="myform">
<table>
<tr xmlns="">
<td>
<label>
民族</label>
</td>
<td>
<input id="nation" name="nation" class="InputValue" type="text" />
</td>
</tr>
<tr xmlns="">
<td>
<label>
爱好</label>
</td>
<td>
<div id="hobby" style="needcheck: true; isnull: false; des: 爱好">
<input name="hobby" value="车" type="checkbox" checked="" />车<input name="hobby" value="特卖"
type="checkbox" />特卖</div>
</td>
</tr>
</table>
<input type="button" value="button" οnclick="test();" />
</form>
</body>
</html>
更多推荐
所有评论(0)