為什么<script type="text/javascript">加了type就不能運行第二個按鈕了呢
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>DOM事件</title>
</head>
<body>
<div ID="BOX">
<input type="button" id="btn1" value="按鈕1" onclick="showMessae()">
<input type="button" id="btn2" value="按鈕2">
</div>
<script type="text/javascript">
function showMessae () {
alert('按鈕1');
}
var btn2=document.getElementById("btn2");
//給btn2添加事件
btn2.onclick=function(){
alert('這是通過dom添加的事件!');
}
</script>
</body>
</html>
為什么加了type="text/script"就不能解析dom了呢???????
這樣第二個按鈕事件出不來!
//#############################################################
這樣才能正常運行
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>DOM事件</title>
</head>
<body>
<div ID="BOX">
<input type="button" id="btn1" value="按鈕1" onclick="showMessae()">
<input type="button" id="btn2" value="按鈕2">
</div>
<script>
function showMessae () {
alert('按鈕1');
}
var btn2=document.getElementById("btn2");
//給btn2添加事件
btn2.onclick=function(){
alert('這是通過dom添加的事件!');
}
</script>
</body>
</html>
2016-09-26
可以運行啊,你在哪個瀏覽器不能運行?