面试题:写一个行为样式结构相分离的网站?
刚开始不懂,后来明白,行为就是js,样式就是css,结构就是Html.要各自独立。
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Title</title> 6 <style> 7 #i1{ 8 width: 300px; 9 height: 500px; 10 background-color: orangered; 11 margin: 0 auto; 12 } 13 </style> 14 </head> 15 <body> 16 <div id="i1">test div 1</div> 17 18 19 <script> 20 var tag = document.getElementById('i1'); 21 tag.onclick = function () { 22 tag.style.backgroundColor = 'red'; 23 } 24 </script> 25 </body> 26 </html>