日期:2014-05-16  浏览次数:20374 次

js :parentNode,firstChild,parentNode,nextSibling;

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> ?
<html> ?
??? <head> ?
??????? <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> ?
??????? <title>Untitled Document</title> ?
??????? <script language="JavaScript"> ?
?? ??? ??? ? function test1() {
?? ??? ??? ??? ? var node = document.getElementById("imgid2"); ?
?? ??? ??? ??? ? var pimg = node.parentNode.firstChild;
?? ??? ??? ??? ? var inpu = node.parentNode.nextSibling;
?? ??? ??? ??? ? alert(pimg.value);
?? ??? ??? ??? ? alert(inpu.value);
?? ??? ??? ? }
??????? </script> ?
??? </head> ?
??? <body> ?
?? ?<div>
?? ??? ?<a id ="aid">
?? ??? ??? ?<img id ="imgid" value="img1" />
?? ??? ??? ?<img id ="imgid2" value="img2" />
?? ??? ?</a>
?? ??? ?<input type="text" value="input"/>
?? ?</div>
?? ??? ?<input type="button" value="GOGO" onClick="test1();" /> ?
??? </body> ?
</html>?