js怎么取出页面a标签的href值

时间:2024-10-13 08:46:51

1、新建一个html文件,命名为test.html,用于讲解js怎么取出页面a标签的href值。

js怎么取出页面a标签的href值

2、在test.html文件内,在p标签内,使用a标签创建一个链接,并设置href属性值为“链接”。

js怎么取出页面a标签的href值

3、在test.html文件内,设置a标签的id为mytest,主要用于下面通过该id获得a标签对象。

js怎么取出页面a标签的href值

4、在test.html文件内,使用button标签创建一个按钮,按钮名称为“获得type属性值”。

js怎么取出页面a标签的href值

5、在test.html文件中,给button按钮绑定onclick点击事件,当按钮被点击时,执行gethref()函数。

js怎么取出页面a标签的href值

6、在js标签中,创建getvalue()函数,在函数内,使用getElementBy诔罨租磊Id()方法通过id(mytest)获得a标签对象,使用attri芟鲠阻缒butes来获得href属性对象,通过nodeValue属性获得href的值。

js怎么取出页面a标签的href值

7、在浏览器打开test.html文件,点击按钮,查看结果。

js怎么取出页面a标签的href值
© 手抄报圈