js获取html对象
来源:互联网 发布:美工专用笔记本 编辑:程序博客网 时间:2024/06/08 03:36
使用js获取html对象有三种方法: getElementById, getElementsByName和getElementsByTagName。
以下是一个html文档片段:
<p id="pa">It is the first paragraph!</p><p name="pb">It is the second paragraph!</p><p name="pb">It is the third paragraph!</p><table border="1"> <tr> <th>Name</th> <th>Age</th> <th>Gender</th> </tr> <tr> <td>Alice</td> <td>22</td> <td>female</td> </tr> <tr> <td>Bob</td> <td>23</td> <td>male</td> </tr> <tr> <td>David</td> <td>22</td> <td>male</td> </tr> </table> <script> var pa = document.getElementById('pa'); console.log('pa:', pa); var ps = document.getElementsByName('pb'); console.log('ps:', ps); var tds = document.getElementsByTagName('td'); console.log('tds:', tds); </script>
下面是该页面内容和打印在控制台上的内容截图:
这下就看的清楚了,通过getElementById只能获取指定id的单个html对象。而通过标签的name或者标签的名字就能获取到一组html对象了。
ps: csdn上使用的markdown编辑器好像有些问题,好像不太能支持自定义代码片段。下面对照我本地的md试试看。
1 0
- js获取html对象
- js获取html的对象样式
- JS获取html对象的几种方式介绍
- js获取html节点
- js获取html内容
- js获取html标签
- js获取html元素
- js获取html内容
- JS获取HTML样式
- js获取html标签
- js HTML DOM对象
- js获取对象
- js获取event对象
- 获取js事件对象
- js获取元素对象
- js获取表单对象
- js获取事件对象
- js获取iframe对象
- C++中静态变量static使用说明
- JavaWEB学习记录--HtmlUnit爬网页数据
- 【数据结构】算法9.1 顺序表查找-顺序查找
- 1059. C语言竞赛(20)
- 使用SimpleAdapter作为适配器时,支持三种类型的 View
- js获取html对象
- java常用排序算法之插入排序
- 输入框input类型为number时,去掉上下箭头方式
- 机房收费文档(二)系统开发计划
- 【数据结构】算法9.2 有序表查找-折半查找
- AC自动机-题目集合
- 51nod-1010 只包含因子2 3 5的数
- Java NIO 之 ServerSocketChannel SocketChannel
- Linux(ubuntu 14.04)下安装jdk(1.8)以及eclipse 最新版本Neon的安装