Download Fore_End/JavaScript/DOM/06_Element对象.html from zxy0307/JavaWeb: direct link, hf CLI and curl.
- Browser
- Download file 1.19 kB
-
https://huggingface.co/zxy0307/JavaWeb/resolve/main/Fore_End/JavaScript/DOM/06_Element%E5%AF%B9%E8%B1%A1.html
- Command line
-
hf download hf://zxy0307/JavaWeb/Fore_End/JavaScript/DOM/06_Element对象.html
-
curl -L -o 06_Element对象.html https://huggingface.co/zxy0307/JavaWeb/resolve/main/Fore_End/JavaScript/DOM/06_Element%E5%AF%B9%E8%B1%A1.html
1.19 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title>Element对象</title> | |
| </head> | |
| <body> | |
| <a>点我试一试</a> | |
| <input type="button" id="btn_set" value="设置属性"> | |
| <input type="button" id="btn_remove" value="删除属性"> | |
| <script> | |
| /* | |
| Element:元素对象 | |
| 1. 获取/创建:通过document来获取和创建 | |
| 2. 方法: | |
| 1. removeAttribute():删除属性 | |
| 2. setAttribute():设置属性 | |
| */ | |
| //获取设置属性btn | |
| var btn_set = document.getElementById("btn_set"); | |
| btn_set.onclick = function() { | |
| var element_a = document.getElementsByTagName("a")[0]; | |
| element_a.setAttribute("href","https://www.baidu.com"); | |
| } | |
| // | |
| var btn_remove = document.getElementById("btn_remove"); | |
| btn_remove.onclick = function() { | |
| var element_a = document.getElementsByTagName("a")[0]; | |
| element_a.removeAttribute("href"); | |
| } | |
| </script> | |
| </body> | |
| </html> |