Element:元素对象,标签对象,枝叶
创建
通过document获取和创建
方法
①removeAttribute():删除属性
②setAttribute():设置属性
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <a>点我试试</a> <input id="set" type="button" value="设置属性"> <input id="remove" type="button" value="删除属性"> <script> //获取按钮 var set = document.getElementById("set"); set.onclick=function () { //1.获取a标签 var a = document.getElementsByTagName("a")[0]; a.setAttribute("href","https://cn.bing.com/?FORM=Z9FD1"); } //获取按钮 var remove = document.getElementById("remove"); remove.onclick=function () { //1.获取a标签 var a = document.getElementsByTagName("a")[0]; a.removeAttribute("href"); } </script> </body> </html>