[JavaScript] internal and external way of introduction

1. Internal introduced manner:

  • script type attribute defaults to "text / javascript", you can not write
. 1  < Script type = "text / JavaScript" > 
2              function the init () {
 . 3  //                 // Case II: writing the display image rotation operation timing (three seconds) 
. 4  //                 the window.setInterval ( "changeImg ()", 3000); // window can be omitted 
. 5                  
. 6                  @ case 3: 1 ad image display timing setting operation. 
7                  // here not add var: var plus local variable, global variable without var 
. 8                  Time = the setInterval ( " showAd () " , 3000 );
 . 9              }
 10              
. 11              // writing function 
12 is              var I=  0 ;
 13 is              function changeImg () {
 14                  I ++ ;
 15                  // get image position and sets the src attribute value 
16                  document.getElementById ( " IMG1 " ) .src =  " ../img/ "  + I +  " .jpg " ;
 . 17                  IF (I ==  2 ) {
 18 is                      I =  0 ;
 . 19                  }
 20 is              }
 21 is              
22 is              //2. The function of writing display ad image 
23 is              function showAd () {
 24                  // 3. Ad image acquisition position 
25                  var AdeLE, an Austrian = document.getElementById ( " IMG2 " );
 26 is                  // 4. modify elements inside attribute allowed to display 
27                  adEle.style.display = " Block " ;
 28                  // 5. the operation timing of clear image display 
29                  the clearInterval (Time);
 30                  // 6. the timing of the operation is provided hidden image 
31 is                  Time = the setInterval ( " hiddenAd () " , 3000 );
32                  
33 is              }
 34              // function written hide 7. 
35              function hiddenAd () {
 36                  // 8. The acquired image position and sets the value of the style attribute display none 
37 [                  document.getElementById ( " IMG2 " ) .style.display = " none " ;
 38 is                  // 9. the timing of the operation to clear the hide 
39                  the clearInterval (Time);
 40              }
 41 is              
42 is          </ Script >

 

2. External introduced:

  •  Js create a file, writing Javascript code in it, in the html file using the script src attribute tag introduced into the external file js
<script type="text/javascript" src="1.js"></script>

 

1.js file:

. 1  function the init () {
 2      //                 // Case II: writing the display image rotation operation timing (three seconds) 
. 3      //                 the window.setInterval ( "changeImg ()", 3000); // can be omitted window 
4  
5      // . case 3: 1 to set the display operation timing of image ads 
6      // here not add var: var plus local variable, global variable without var 
. 7      Time = the setInterval ( "showAd ()", 3000 );
 . 8  }
 . 9  
10  // Write function 
. 11  var I = 0 ;
 12 is  
13 is  function changeImg () {
 14      I ++ ;
 15      // get image position and sets the src attribute value 
16     . document.getElementById ( "IMG1") the src = "../img/" I + + ".jpg" ;
 . 17      IF (I == 2 ) {
 18 is          I = 0 ;
 . 19      }
 20 is  }
 21 is  
22 is  // 2. ad image writing display function 
23 is  function showAd () {
 24      // 3. ad image acquisition position 
25      var AdeLE, an Austrian = document.getElementById ( "IMG2" );
 26 is      // 4. modify elements inside attribute allowed to display 
27      AdeLE, an Austrian. =. style.display "Block" ;
 28      // 5. the operation timing of clear image display 
29      the clearInterval (Time);
 30      //6. Set the hide operation timing 
31 is      Time = the setInterval ( "hiddenAd ()", 3000 );
 32  
33 is  }
 34 is  // function written hide 7. 
35  function hiddenAd () {
 36      // 8. The image acquiring position and set the display style attribute is none 
37 [      document.getElementById ( "IMG2"). style.display = "none." ;
 38 is      // 9. the timing of the operation to clear the hide 
39      the clearInterval (Time);
 40 }

 

Guess you like

Origin www.cnblogs.com/musecho/p/11022367.html