Highlight cell border color when click, change back when click to others

后端 未结 1 848
说谎
说谎 2021-01-25 04:37

I have the code below:



        
相关标签:
1条回答
  • 2021-01-25 04:46
        var redNow = 1;
        function highlight(cell) {
            redNow == 1 ? redNow = 0 : redNow.style.borderColor = "black";
            redNow = cell;
            cell.style.borderColor = "red";
        }
        td {
        		cursor: pointer;
        	}
       <table border="1">
        <tr>
            <td onmousedown="highlight(this);">Cell 1</td>
            <td onmousedown="highlight(this);">Cell 2</td>
            <td onmousedown="highlight(this);">Cell 3</td>
        </tr>
        <tr>
            <td onmousedown="highlight(this);">Cell 4</td>
            <td onmousedown="highlight(this);">Cell 5</td>
            <td onmousedown="highlight(this);">Cell 6</td>
        </tr>
        <tr>
            <td onmousedown="highlight(this);">Cell 7</td>
            <td onmousedown="highlight(this);">Cell 8</td>
            <td onmousedown="highlight(this);">Cell 9</td>
        </tr>
    </table>
    0 讨论(0)
提交回复
热议问题