<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
<style text="text/css">
body{
background-color:pink;
font-size:24px;
text-align:center;
}
p{
line-height:0.86;
}
</style>
<script type="text/javascript">
function clickme(x){
var dom=document.getElementsByTagName("p");
//该点击的节点
for(var i=0;i<dom.length;i++){
if(x==dom[i]){
//alert(x.id);
alert(i+1);
break;
}
}
}
function add_jd(){
var id_str=document.getElementsByTagName("p").length+1;
var para=childpoint=document.createElement("p");
para.id="aa".concat(id_str);
para.innerHTML=para.id;
para.οnclick=function (){
var dom=document.getElementsByTagName("p");
for(var i=0;i<dom.length;i++){
if(this==dom[i]){
//alert(this.id);
alert(i+1);
break;
}
}
}
document.getElementsByTagName("body")[0].appendChild(para);
}
</script>
</head>
<body>
<input οnclick="add_jd()" type="button" value="点击我吧"></input>
<p id="first" οnclick="clickme(this)">first 1</p>
<p id="second" οnclick="clickme(this)">second 2</p>
<p id="third" οnclick="clickme(this)">third 3</p>
<p id="fourth" οnclick="clickme(this)">fourth 4</p>
<p id="fifth" οnclick="clickme(this)">fifth 5</p>
<p id="sixth" οnclick="clickme(this)">sixth 6</p>
</body>
</html>
当页面上任意一个链接被点击的时候,alert出这个链接在页面上的顺序号
最新推荐文章于 2022-12-02 10:18:48 发布