1."javascript:"伪协议
2.平稳退化
<a href="http://www.cnblogs.com/anyboo" οnclick="popUp(this.href);return false;">Example</a>
3.向CSS学习——结构与样式的分离
4.渐进增强
CSS 代码负责提供关于“表示”的信息,Javascript代码负责提供关于“行为”的信息。
5.分离Javascript
element.event = action ...
getElementById(id).event = action
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 var links = document.getElementByTagName('a'); 2 3 for(var i = 0;i<links.length;i++){ 4 5 if(links[i].getAttribute('class') == 'popup'){ 6 7 links[i].onclick = function(){ 8 9 popUp(this.getAttribute('href')); 10 11 return false; 12 13 } 14 15 } 16 17 }
6.向后兼容 对象检测
if(method){
statements
}
7.减少DOM访问和标记使用 合并和放置脚本 压缩脚本