当页面上任意一个链接被点击的时候,alert出这个链接在页面上的顺序号
2016-01-10 00:21
555 查看
<!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.onclick=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 onclick="add_jd()" type="button" value="点击我吧"></input> <p id="first" onclick="clickme(this)">first 1</p> <p id="second" onclick="clickme(this)">second 2</p> <p id="third" onclick="clickme(this)">third 3</p> <p id="fourth" onclick="clickme(this)">fourth 4</p> <p id="fifth" onclick="clickme(this)">fifth 5</p> <p id="sixth" onclick="clickme(this)">sixth 6</p> </body> </html>
相关文章推荐
- iOS开发CoreAnimation解读之二——对CALayer的分析
- iOS开发CoreAnimation解读之一——初识CoreAnimation核心动画编程
- 【RBAC】打造Web权限控制系统
- Leetcode: Range Sum Query 2D - Immutable
- 用PHP编写一个APP的API
- SampleManager 11安装备忘
- chapter16:例行性工作(crontab)之一:什么是例行性工作与实际运行单一工作调度
- 小林的第一篇博客
- java基础学习笔记2
- 最近考试 等到15号左右开始学习再更新吧
- C#实现字符串SHA-512加密算法
- Linux ->> Ping命令
- 十六进制转十进制
- 树莓派的安装
- Linux网络配置命令
- Jackson - ObjectMapper
- AAC音频格式简析
- 输出二维数组
- Java Swing JTable 表格【2:创建空表格】
- 常用排序算法性能分析