<!DOCTYPE >
<html>
<meta charset="utf-8">
<title>js引入方式</title>
<head>
<style>
#ball{
width:100px;
height:80px;
padding-top:20px;
border-radius:50%;
background-color:red;
position:relative;
font-size:12px;
}
</style>
</head>
<body>
<h1 onclick="alert('我要成为全栈工程师')">方法一,在元素事件方法属性上是写入js</h1>
<div id="ball" onclick="running()">方法二,在script中写入js</div>
<script>
var ball = document.getElementById('ball');
function running(){
var count = 0;
var timer = setInterval(function (){
if (count < 100) {
ball.style.width = ball.style.height = ball.style.top = ball.style.left = count + "px";
count++;
} else {
clearInterval(timer);
}
}, 100);
}
</script>
/*方法三外部引入js文件*/
<script src="ball.js"></script>
</body>
</html>