js document用法

 时间:2026-02-16 21:44:52

1、使用sublime text2编写html文件

2、document的相关方法:

getElementById()     返回对拥有指定 id 的第一个对象的引用。getElementsByName()     返回带有指定名称的对象集合。getElementsByTagName()     返回带有指定标签名的对象集合。

3、内容:

<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script>function changeLink(){// document.getElementById('myAnchor').innerHTML="22";// //document.getElementById('myAnchor').outerHTML="longlong";// document.getElementById('myAnchor').href="http://www.w3school.com.cn";// document.getElementById('myAnchor').target="_blank";// var myAnch = document.getElementById('myAnchor');// alert(myAnch.innerHTML); //output:  微软// alert(myAnch.outerHTML); //output: <a id="myAnchor" href="http://www.microsoft.com">微软</a> // alert(document.innerHTML); //output:  undefined// alert(document.outerHTML); //output: undefined// alert(document.body.innerHTML); //output: /*<a id="myAnchor" href="http://www.microsoft.com">微软</a><input type="button" onclick="changeLink()" value="更改链接">*/ // alert(document.body.outerHTML); //output: 整个body/*<body><a id="myAnchor" href="http://www.microsoft.com">微软</a><input onclick="changeLink()" value="更改链接" type="button"></body>*/// alert(document.html.innerHTML); //output:  不会显示任何东西// alert(document.html.outerHTML); //output: 不会显示任何东西    var totalContent=document.getElementsByTagName('html')[0].innerHTML;      alert(totalContent);  //output:  head和body的内容}</script></head><body><a id="myAnchor" href="http://www.microsoft.com">微软</a><input type="button" onclick="changeLink()" value="更改链接"></body></html>

4、将网页放到浏览器中,点击按钮,结果:

js document用法

  • VSCODE-GIT提交authentication failed处理方法
  • js如何输出html页面所有div的id属性
  • 如何使用python语言中的array进行访问数组
  • C#DataTable如何设置某一行的颜色
  • 王牌竞速里程碑奖励怎么领取
  • 热门搜索
    北戴河旅游攻略 丽江旅游股票 百色旅游 岳阳旅游 研学旅游 香港旅游攻略 成都旅游地图 旅游的好地方 川西旅游攻略 德国旅游