我目前有一个有效的图像交换代码。但我不想图像交换所有图像。如果希望只能相互交换橙色图像。如果将橙色图像与蓝色或红色图像交换以使橙色与红色或蓝色相同,而不会影响红色或蓝色图像。这是一个示例JsFiddle
需要处理的代码
var pix = document.getElementById("GALLERY").getElementsByTagName("img");
for ( var p = 0; p < pix.length; ++p )
{
pix[p].onclick = picclick;
}
var firstImage = null;
function picclick( )
{
// to cancel a swap, click on first image again:
if ( firstImage == this )
{
this.className = "normal";
firstImage = null;
return;
}
// is this first image clicked on?
if ( firstImage == null )
{
// yes
firstImage = this;
this.className = "highlighted";
document.getElementById('search').value = "";
return; // nothing more to do
}
// aha! second image clicked on, so do swap
firstImage.className = "normal";
var temp = this.src;
this.src = firstImage.src;
firstImage.src = temp;
firstImage = null;
};
PS红蓝也不能互换。
到目前为止我已经尝试过:
我一直在尝试 if 1st_image_clicked=sold.png
then2nd_image_clicked=sold.png
或 if 1st_image_clicked=0-1.png
and 2nd_image_clicked=sold.png
then1st_imagec_licked & 2nd_image_clicked=sold.png