想問(wèn)下代碼的問(wèn)題
<html> <head> <title>我的世界</title> </head> <body> <div?id="box"> <input?type="button"?value="按鈕"?id="btn"?onclick="showmessage()"> <input?type="button"?value="按鈕2"?id="btn2"> <input?type="button"?value="按鈕3"?id="btn3"> </div> <script> function?showmessage(){ alert('Hello?World!') } var?btn2=document.getElementById("btn2"); var?btn3=document.getElementById("btn3"); btn2.onclick=function(){ alert("這是DOM0級(jí)事件處理") } //btn2.onclick=null; /* btn3.addEventListener("click",function(){ alert("DOM2級(jí)事件處理") },false); //btn3.removeEventListener("click",showmessage,false);*/ btn3.attachEvent("onclick",showmessage) </script> </body> </html>
我把這個(gè)代碼放在IE瀏覽器里發(fā)現(xiàn)是字都變成亂碼了,求看看哪里出錯(cuò)了
2017-07-10
在head里加一條<meta charset="utf-8">,意思是編碼格式為utf-8格式的,這樣就不會(huì)亂碼了