Здравствуйте, знатоки JavaScript!))
В нижеприведённом примере требуется, чтобы изображения при клике менялись местами не произвольно, а строго "ходом конём" ("Г").
Пожалуйста, подскажите решение!
<html>
<head>
<script type="text/javascript">
var temp = new Image();
var loc;
var gotit;
function exch(e)
{
var srcElement;
srcElement = e.srcElement ? e.srcElement : e.target;
if (srcElement.className == "click")
{
if (gotit == 1)
{
gotit = 0;
document.images[loc].src = document.images[srcElement.name].src;
document.images[srcElement.name].src = temp.src;
stt=srcElement.name;
}
else
{
gotit = 1;
loc = srcElement.name;
temp.src = document.images[loc].src;
}
}
}
</script>
</head>
<body>
<form onclick="exch(event)">
<table align="center" cellspacing="1" cellpadding="0">
<tr>
<td><img class="click" name="1a1b" src="https://placehold.co/100x100/ff0000/ffff00?font=playfair-display&text=§"></td>
<td><img class="click" name="1a2b" src="https://placehold.co/100x100/ff0000/ffff00?font=playfair-display&text=©"></td>
<td><img class="click" name="1a3b" src="https://placehold.co/100x100/ff0000/ffff00?font=playfair-display&text=π"></td>
<td><img class="click" name="1a4b" src="https://placehold.co/100x100/ff0000/ffff00?font=playfair-display&text=4"></td>
</tr>
<tr>
<td><img class="click" name="2a1b" src="https://placehold.co/100x100/ff0000/ffff00?font=playfair-display&text=≈"></td>
<td><img class="click" name="2a2b" src="https://placehold.co/100x100/ff0000/ffff00?font=playfair-display&text=¶"></td>
<td><img class="click" name="2a3b" src="https://placehold.co/100x100/ff0000/ffff00?font=playfair-display&text=@"></td>
<td><img class="click" name="2a4b" src="https://placehold.co/100x100/ff0000/ffff00?font=playfair-display&text=№"></td>
</tr>
<tr>
<td><img class="click" name="3a1b" src="https://placehold.co/100x100/ff0000/ffff00?font=playfair-display&text=$"></td>
<td><img class="click" name="3a2b" src="https://placehold.co/100x100/ff0000/ffff00?font=playfair-display&text=¿"></td>
<td><img class="click" name="3a3b" src="https://placehold.co/100x100/ff0000/ffff00?font=playfair-display&text=ƒ"></td>
<td><img class="click" name="3a4b" src="https://placehold.co/100x100/ff0000/ffff00?font=playfair-display&text=®"></td>
</tr>
</table>
</form>
</body>
</html>