javascript DOM2寻找选择文字路径
2009-09-11 00:31
155 查看
今天在CSDN遇到个帖子,需要得到选中元素的所属DOM结点层次.代码主要涉及的DOM2的几个点.
看下代码就知道了:
看下代码就知道了:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> new document </title> <script type="text/javascript"> function ShowDirection() { var tbl = []; var direct = (document.selection && document.selection.createRange) ? document.selection.createRange().parentElement() // IE : window.getSelection().focusNode.parentNode; // FF do { tbl.push(direct.tagName); } while((direct = direct.parentNode) && (direct !== document.documentElement)); alert(tbl.reverse().join('---->')) } </script> </head> <body> <div>123 <p>456 <span>789 <b>bbbbb </b> </span> </p> <input type="button" value="ShowDirection" onclick="ShowDirection()" /> </body> </html>
相关文章推荐
- 自定义控件之绘图篇(二) —— 路径及文字
- 【转】Scott_ASP.NET MVC框架(第二部分) URL路径选择
- 选择开发语言和学习的路径(这个标题可能有点不准确)
- iOS - 压缩控制器作用范围,路径push选择
- java地图路径染色寻找算法
- 用jquery获得选择的checkbox的文字值
- 游戏开发中的人工智能(六):基本路径寻找及航点应用
- 游戏开发中的人工智能(七):A* 路径寻找算法
- 在光标选择处插入指定文字
- iOS 图片选择的路径处理(转)
- MFC选择文件存放路径
- android Graphics(二):路径及文字
- DFS寻找路径~
- WEB下载控件/WEB路径选择控件/AJAX下载文件(需求:一政府要求有的文件内部只能下载一次,当然是用户成功将文件下载完)
- 寻找最短路径BFS
- 新建文件对话框,选择路径,新建并写入文件
- ckfinder.net完全讲解六(模拟选择ckfinder选择按钮,并保存上传文件路径)
- Java文件下载选择路径注意事项
- 清空AsyncFileUpload 选择的文件路径
- Android自由选择TextView的文字