运行多个javascripts来更改图像

时间:2013-09-01 21:46:45

标签: javascript image

有问题我不能让两个改变只有1将工作,我需要两个切换器在我的网站上工作任何帮助将不胜感激 提前谢谢你 这是我的代码,我认为它有你需要的一切,看看它到底在做什么

   <html>
    <body>

     <img id="imageToSwap" src="http://ideviceguys.com/wp- content/uploads/2013/09/blkscreen.png" />

     <br/><br/>

     <select id="screens" onChange="swapImage()">
     <option value="http://ideviceguys.com/wp-   content/uploads/2013/09/blkscreen.png">Black</option>
    <option value="http://ideviceguys.com/wp-content/uploads/2013/09/whtscreen.png">White</option>
     <option value="http://ideviceguys.com/wp-content/uploads/2013/09/ltbluescreen.png">Light Blue</option>
     <option value="http://ideviceguys.com/wp-content/uploads/2013/09/yellowscreen.png">Yellow</option>
     <option value="http://ideviceguys.com/wp-content/uploads/2013/09/pinkscreen.png">Pink</option>
    <option value="http://ideviceguys.com/wp-content/uploads/2013/09/redscreen.png">Red</option>
   </select>
    <script type="text/javascript">
    function swapImage(){
var image = document.getElementById("imageToSwap");
var dropd = document.getElementById("screens");
image.src = dropd.value;    
    };
 </script>
 </body>
 </html>


<html>
<body>

 <img id="colorframes" src="http://ideviceguys.com/wp-content/uploads/2013/09/blkframe.png" />

<br/><br/>

  <select id="frames" onChange="swapImage()">
  <option value="http://ideviceguys.com/wp-content/uploads/2013/09/blkframe.png">Black</option>
  <option value="http://ideviceguys.com/wp-content/uploads/2013/09/whtframe.png">White</option>
  <option value="http://ideviceguys.com/wp-content/uploads/2013/09/ltblueframe.png">Light Blue</option>
 <option value="http://ideviceguys.com/wp-content/uploads/2013/09/goldframe.png">Gold</option>
 <option value="http://ideviceguys.com/wp-content/uploads/2013/09/pinkframe.png">Pink</option>
 <option value="http://ideviceguys.com/wp-content/uploads/2013/09/redframe.png">Red</option>
 </select>
 <script type="text/javascript">
 function swapImage(){
var image = document.getElementById("colorframes");
var dropd = document.getElementById("frames");
image.src = dropd.value;    
   };
   </script>
   </body>
   </html>

1 个答案:

答案 0 :(得分:0)

像这样? http://jsfiddle.net/DNYm4/

我添加了

      var image2 = document.getElementById("colorframes");
      image2.src = dropd.value;