Markieren Sie die Farbe des Zellenrahmens, wenn Sie auf klicken, und ändern Sie sie, wenn Sie auf andere klicken.

Ich habe den folgenden Code:

function highlight(cell){
		cell.style.borderColor = "red";
	}
	
	function originalColor(cell){
		cell.style.borderColor = "black";
	}
td{
		cursor: pointer;
	}
<table border="1">
	<tr>
	<td  onmousedown="highlight(this);" onblur="originalColor(this);">Cell 1</td>
	<td  onmousedown="highlight(this);" onblur="originalColor(this);">Cell 2</td>
	<td  onmousedown="highlight(this);" onblur="originalColor(this);">Cell 3</td>
	</tr>
	<tr>
	<td  onmousedown="highlight(this);" onblur="originalColor(this);">Cell 4</td>
	<td  onmousedown="highlight(this);" onblur="originalColor(this);">Cell 5</td>
	<td  onmousedown="highlight(this);" onblur="originalColor(this);">Cell 6</td>
	</tr>
	<tr>
	<td onmousedown="highlight(this);" onblur="originalColor(this);">Cell 7</td>
	<td onmousedown="highlight(this);" onblur="originalColor(this);">Cell 8</td>
	<td onmousedown="highlight(this);" onblur="originalColor(this);">Cell 9</td>
	</tr>
	</table>

Es wird den Rand rot hervorheben, wenn auf die andere Zelle geklickt wird. Es wird angenommen, dass die Farbe wieder schwarz wird, aber es funktioniert nicht. Ich versucheonmouseup, onmouseover, es funktioniert nicht so wie ich es will.

Die Technik, die ich ausprobiert habe, ist die Verwendung vontabindex, Es klappt; Dies kann jedoch eine Zelle hervorheben. Wenn ich versuche, zwei Zellen gleichzeitig auszuwählen, funktioniert dies nicht. Kann mir jemand helfen?

Antworten auf die Frage(4)

Ihre Antwort auf die Frage