第三十八节 JavaScript中的window.location属性二
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Document</title> 6 <script type="text/javascript"> 7 window.onload = function(){ 8 var oBody = document.getElementById('body01'); 9 var sData = window.location.search; // 通过在地址后加?aa=1给值 10 var hData = window.location.hash; // 通过在地址后加#aa=1给值 11 if (sData!='') 12 { 13 var iRr = parseInt(sData.split('=')[1]); 14 if (iRr === 1) 15 { 16 oBody.style.backgroundColor = 'red'; 17 } 18 else if(iRr == 2) 19 { 20 oBody.style.backgroundColor = 'green'; 21 } 22 } 23 } 24 </script> 25 <style type="text/css"> 26 body{ 27 background-color: gold; 28 } 29 </style> 30 </head> 31 <body id="body01"> 32 33 </body> 34 </html>