<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
#a{
text-align: center;
margin-left: 400px;
margin-top: 80px;
border: #4CAF50 30px groove;
padding-top: 10px;
width: 600PX;
}
</style>
</head>
<body>
<div id="a">
<h1>hello</h1>
<p id="demo">这段点击就改变</p>
<button type="button" onclick="myFunction()">点我</button>
<p><b>myFunction()函数在外部js文件中</b></p>
</div>
<script src="变换一段文字.js"></script>
</body>
</html>
外部的js文件为:
function myFunction(){
document.getElementById("demo").innerHTML = "hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh";
}