用简单的代码写出效率高的程序

 

  1. <!--这个程序使用了javascript中的this,this可以减少很多不必要的代码量,并且提高代码的效率--> 
  2. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 
  3. <html> 
  4.     <head> 
  5.         <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
  6.         <title>Untitled Document</title> 
  7.         <script language="javascript"> 
  8.             function processData(form){  
  9.                 for (var i = 0; i < form.Beatles.length; i++) {  
  10.                     if (form.Beatles[i].checked) {  
  11.                         break;  
  12.                     }  
  13.                 }  
  14.                 var beatle = form.Beatles[i].value;  
  15.                 var song = form.song.value;  
  16.                 alert("Checking whether"+"   "+ song+"   "+ "features"+"   "+ beatle+"   "+ "...");  
  17.             }  
  18.               
  19.             function verifySong(entry){//这里的entry是随便起的也可以叫别的名  
  20.                 var song = entry.value;  
  21.                 alert("Checking whether" +"   "+ song+"   " + "is a Beatles tune...");  
  22.             }  
  23.         </script> 
  24.     </head> 
  25.     <body> 
  26.         <form onSubmit="return false"> 
  27.             Choose your favorite Beatle:  
  28.             <input type="radio" name="Beatles" value="John Lennon" checked/>John  <!--看到这里的checked了吧可以这样太简单了--> 
  29.             <input type="radio" name="Beatles" value="Paul McCartney"/>Paul  
  30.             <input type="radio" name="Beatles" value="George Harrison"/>George  
  31.             <input type="radio" name="Beatles" value="Ringo Starr"/>Ringo  
  32.             <p> 
  33.                 Enter the name of your favorite Beatles song:  
  34.                 <br> 
  35.                 <input type="text" name="song" value="Eleanor Rigby" onChange="verifySong(this)"/> 
  36.                 <p> 
  37.                 <input type="button" name="process" value="Process Request..." onClick="processData(this.form)"/> 
  38.                 <!--因为这个按钮是要提交表单的,直接将form传到指定的函数中--> 
  39.                 </form> 
  40.             </body> 
  41.  </html> 

哈哈 看到了吧 简单吧