终于搞出来了
document.getElementById(“id”) 通过页面中的标识来获取元素,括号中写入命名的id元素
document.getElementById(‘id’).innerHTML="" 中的innerHTML=“ ”共有两种方法
1.直接获取定义的内容
html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script type="text/javascript">
function changeLink(){
alert(document.getElementById('myAnchor').innerHTML);
}
</script>
</head>
<body>
<a id="myAnchor">Microsoft</a>
<input type="button" οnclick="changeLink()" value="点击">
</body>
</html>
2.通过inerHTML来定义值
html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script type="text/javascript">
function changeLink(){
alert(document.getElementById('myAnchor').innerHTML="hahahah");
}
</script>
</head>
<body>
<a id="myAnchor"></a>
<input type="button" onclick="changeLink()" value="点击">
</body>
</html>