首先,抱歉英语不好。
好吧,我有 3 段,每段都有一些链接,我必须按段显示链接
这是我的 HTML 和 JS 代码:
<head>
<script type="text/javascript">
function pEn(){
var nump=document.getElementsByTagName("p");
var nEn=new Array();
for (var i = 0; i < nump.length; i++) {
nEn=document.getElementsByTagName("a");
for (var j = 0; j < nEn.length; j++) {
alert("Parrafo numero "+(i+1)+": "+nEn[j]);
};
};
}
</script>
</head>
<body>
<p>
<a href="http://www.google.es">First link</a>
<a href="http://www.stackoverflow.com">Second link</a>
</p>
<p>
<a href="http://www.neoteo.com">Third link</a>
</p>
<p>
<a href="http://fp.edu.gva.es/">Fourth link</a>
</p>
<div>
<button onclick="pEn()">Links by paragraph</button>
</div>
</body>
我想得到的是:P1:www.fdsjkfls.com,P1:www.fjkdslfjsklo.com,P2:www.sdklf.com,P3:www.vnsdwo.com
不是这个:P1:www.fdsjkfls.com,P1:www.fjkdslfjsklo.com,P1:www.sdklf.com,P1:www.vnsdwo.com,P2:www.fdsjkfls.com,P2:www.fjkdslfjsklo.com , P2: www.sdklf.com, P2: www.vnsdwo.com, ...
有什么建议吗?