首页 > 解决方案 > 无法使用 javascript 更改图像 src

问题描述

当我单击 2 img not identique 我希望它更改为另一个 img 但它无法工作

function changeImage1()
{
  var img1 =document.getElementById("image_change");
  var img2 =document.getElementById("image_change1");
  var img3 =document.getElementById("image_change2");

  if(img1.src===img2.src)
  {
    setTimeout( function ( ) { alert( "identique" ); }, 1000 );
  }
  else if(img1.src === img3.src)
  {
    document.getElementById("image_change").src="img111.jpg";
    document.getElementById("image_change2").src="img111.jpg";

    setTimeout(changeImage1, 1000);
  }
}
<table>
<tr>
    <td >
        <img src="img111.jpg" alt="img1"
           width="100" height="100"
           onClick="changeImage(this.id); changeImage1(this.id)"
           id="image_change">
    </td>
    <td >
        <img src="img111.jpg" alt="img3"
          width="100" height="100" 
          onClick="changeImage(this.id); changeImage1(this.id)"
          id="image_change2">
    </td>
    <td>
        <img src="img111.jpg" alt="img1" 
          width="100" height="100" 
          onClick="changeImage(this.id); changeImage1(this.id)"
          id="image_change1">
    </td>
</tr>
<table>

标签: javascript

解决方案


推荐阅读