如何将js与HTML完全脱离

先举出一个例子:

1 var sound='Roar!';
2 function myOrneryBeast(){
3     alert(this);
4     this.style.color='green';//this指代的是window对象
5     alert(sound);
6 }
7 window.onload=function(){
8     document.getElementById("a").onclick=myOrneryBeast;//将HTML中的点击事件移到js中了
9 }
posted @ 2015-02-04 18:06  小军的代码库  阅读(180)  评论(0编辑  收藏  举报