我期望元素id="colorDisp"
在我運行下列其中一個函數時改變顏色,但代替body
元素更改顏色。下面單擊不同元素時更改元素的背景顏色
代碼:
function red()
\t {
\t \t document.body.style.backgroundColor = "red";
\t }
function blue()
\t {
\t \t document.body.style.backgroundColor = "blue";
\t }
function yellow()
\t {
\t \t document.body.style.backgroundColor = "yellow";
\t }
function green()
\t {
\t \t document.body.style.backgroundColor = "green";
\t } \t
function orange()
\t {
\t \t document.body.style.backgroundColor = "orange";
\t }
function violet()
\t {
\t \t document.body.style.backgroundColor = "violet";
\t }
function grey()
\t {
\t \t document.body.style.backgroundColor = "grey";
\t }
function black()
\t {
\t \t document.body.style.backgroundColor = "black";
\t }
function cream()
\t {
\t \t document.body.style.backgroundColor = "#ffe6e6";
\t }
function fushia()
\t {
\t \t document.body.style.backgroundColor = "#ff00bf";
\t }
function white()
\t {
\t \t document.body.style.backgroundColor = "white";
\t }
<center>
\t <table style="padding-top: 200px;font-size:45">
\t \t <tr>
\t \t \t <td style="background-color:#ff0040"><a href = "#" onclick = "red()">red</a></td>
\t \t \t <td style="background-color:#00bfff"><a href = "#" onclick = "blue()">blue</a></td>
\t \t \t <td rowspan="5"width="300px" id="colorDisp" style="background-color:black"></td>
\t \t </tr>
\t \t <tr>
\t \t \t <td style="background-color:#ffff00"><a href = "#" onclick = "yellow()">yellow</a></td>
\t \t \t <td style="background-color:#80ff00"><a href = "#" onclick = "green()">green</a></td>
\t \t </tr>
\t \t <tr>
\t \t \t <td style="background-color:#ffbf00"><a href = "#" onclick = "orange()">orange</a></td>
\t \t \t <td style="background-color:#8000ff"><a href = "#" onclick = "violet()">violet</a></td>
\t \t </tr>
\t \t <tr>
\t \t \t <td style="background-color:#808080"><a href = "#" onclick = "grey()">grey</a></td>
\t \t \t <td style="background-color:#000000"><a href = "#" onclick = "black()">black</a></td>
\t \t </tr>
\t \t <tr>
\t \t \t <td style="background-color:#ffe6e6"><a href = "#" onclick = "cream()">cream</a></td>
\t \t \t <td style="background-color:#ff00bf"><a href = "#" onclick = "fushia()">fushia</a></td>
\t \t </tr>
\t </table>
\t
</center>
Example output for the code above:
[1]http://i.imgur.com/lhqdFoi.jpg
This is sample output for my question
[2]http://i.imgur.com/cZw4iT3.jpg
什麼是你的問題? – nnnnnn
它發佈在第二張圖片,但無論如何,當你點擊紅色的原始代碼時,背景顏色將變成紅色,但我想要在td id:colorDisp或表 –
中的特定數據中具有背面顏色,非常感謝你們尋求幫助。我在學 –