Ajax学习笔记(1)------关于DOM的代码

多个方法做图片交换:

  1. < html >
  2.   < head >
  3.    < title > Magic Hat </ title >
  4.   
  5.    < script   language = "javascript"   >
  6.   function showRabbit1() {
  7.   var  hatImage = document .getElementById("topHat");
  8.   var  newImg = document .createElement("img");
  9.   newImg.setAttribute("src","images/rabbit-hat.gif");
  10.   var  imgParent = hatImage .parentNode;
  11.   
  12.   //两步完成
  13.   imgParent.insertBefore(newImg,hatImage);
  14. imgParent.removeChild(hatImage);
  15.  var  buttonEmement = document .getElementByTd("hocusPocus");
  16. button.setAttribute("value", "Get back in that hat!");
  17.   
  18. }  
  19.  function showRabbit2() {
  20.   var  hatImage = document .getElementById("topHat");
  21.   var  newImg = document .createElement("img");
  22.   newImg.setAttribute("src","images/rabbit-hat.gif");
  23.   var  imgParent = hatImage .parentNode;
  24.  //一步完成,第一种
  25.   imgParent.replaceChild(newImg,hatImage);
  26.   var  buttonEmement = document .getElementByTd("hocusPocus");
  27. button.setAttribute("value", "Get back in that hat!");
  28.   
  29. }  
  30.    function showRabbit3() {
  31.             var  hatImage = document .getElementById("topHat");
  32.             hatImage.setAttribute("src","images/rabbit-hat.gif");
  33.             var  buttonEmement = document .getElementById("hocusPocus");
  34.             buttonEmement.setAttribute("value", "Get back in that hat!");
  35.              buttonEmement.onclick = hiddenRabbit ;
  36.   
  37.             } 
  38.     function hiddenRabbit(){
  39.             var  hatImage = document .getElementById("topHat");
  40.             hatImage.setAttribute("src","images/topHat.gif");
  41.             var  buttonEmement = document .getElementById("hocusPocus");
  42.             buttonEmement.setAttribute("value", "Hocus Pocus!");
  43.              buttonEmement.onclick = showRabbit3 ;
  44.             } 
  45.    </ script >
  46.   </ head >
  47.   < body >
  48.    < h1   align = "center" > Welcome to the DOM Magic Shop! </ h1 >
  49.    < form   name = "magic-hat" >
  50.     < p   align = "center" >
  51.      < img   src = "images/topHat.gif"   width = "300"   height = "225"   id = "topHat"   />
  52.      < br   />
  53.      < br   />
  54.      < input   type = "button"   id = "hocusPocus"   value = "Hocus Pocus!"   onClick = "showRabbit3();"   />
  55.      
  56.     </ p >
  57.    </ form >                                                                      
  58.   </ body >
  59. </ html >

你可能感兴趣的:(Ajax学习笔记(1)------关于DOM的代码)