大家好,又见面了,我是你们的朋友全栈君。
<!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>
//x下面的是我测试写的
<!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 pimg1=node.parentNode.childNodes[1];
var inpu = node.parentNode.nextSibling;
var iPar=node.parentNode.parentNode;
var inpu1=iPar.childNodes[0];
alert(pimg.value+”–“+pimg1.value);
alert(inpu.value+”–“+iPar.innerText+”–“+iPar.childNodes.length);
for(i=0;i<iPar.childNodes.length;i++)
{
alert(iPar.childNodes[i].value);
}
}
</script>
</head>
<body>
<div>
<a id =”aid”>
<img id =”imgid” value=”img1″ /><img id =”imgid2″ value=”img2″ /><img id =”imgid2″ value=”img3″ /><img id =”imgid2″ value=”img4″ />
</a>456
<input type=”text” value=”input”/>
<input type=”text” value=”input2″/>
<input type=”text” value=”input3″/>
<input type=”text” value=”input4″/>
</div>
<input type=”button” value=”GOGO” onClick=”test1();” />
</body>
</html>
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/159897.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...