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 >
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值