我應該創建一個表格,用戶將輸入其數據。 所以我們有產品名稱和價格和計數作爲我們的專欄。如何更改表格中只有一行的顏色(HTML/JavaScript)
在此之後數據是由用戶填充「薩姆」欄應在自動填寫這是價格乘以計數。
我已經完成了程序,直到這裏。 但是我有一個問題的延續問題:
我應該改變顏色具有最高金額到BLUE 行和改變顏色產品的排的這是最便宜的至RED。
怎麼辦?我已經爲此工作了近3個小時,而且我無法通過老師教給我的任何方式來解決這個問題。
在此先感謝。
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<style>
p{color:#F00};
</style>
<body>
<p> Please fill in the table and then click on "Submit Data": </p>
<table bordercolor="#333366" border="5">
<tr>
<td> <font style="background-color:#0F0"> Name of Product </td>
<td> <font style="background-color:#0F0"> Price </td>
<td> <font style="background-color:#0F0"> Count </td>
</tr>
<tr>
<td> <input type="text" id="textbox1"> </td>
<td> <input type="text" id="textbox2"> </td>
<td> <input type="text" id="textbox3"> </td>
</tr>
<tr>
<td> <input type="text" id="textbox4"> </td>
<td> <input type="text" id="textbox5"> </td>
<td> <input type="text" id="textbox6"> </td>
</tr>
<tr>
<td> <input type="text" id="textbox7"> </td>
<td> <input type="text" id="textbox8"> </td>
<td> <input type="text" id="textbox9"> </td>
</tr>
</table>
<input type="button" value="Submit Data" id="Submit" onClick="Submit()">
</body>
<script>
function Submit()
{
var a=new Array(
(document.getElementById("textbox1").value),
(document.getElementById("textbox2").value),
(document.getElementById("textbox3").value),
(document.getElementById("textbox4").value),
(document.getElementById("textbox5").value),
(document.getElementById("textbox6").value),
(document.getElementById("textbox7").value),
(document.getElementById("textbox8").value),
(document.getElementById("textbox9").value)
);
document.write("<table border='5' bordercolor='#333366'>");
var c=0;
document.write("<tr>");
document.write("<td id='td1'>");
document.getElementById("td1").innerHTML="Name of Product";
document.write("</td>");
document.write("<td id='td2'>");
document.getElementById("td2").innerHTML="Price";
document.write("</td>");
document.write("<td id='td3'>");
document.getElementById("td3").innerHTML="Count";
document.write("</td>");
document.write("<td id='td4'>");
document.getElementById("td4").innerHTML="Sum";
document.write("</td>");
document.write("</tr>");
for(i=0;i<3;i++)
{
document.write("<tr>");
for(j=0;j<4;j++)
{
var sum=a[c-1] * a[c-2];
if(j==3) {document.write("<td>" +sum+ "</td>");}
else
{
document.write("<td>" +a[c]+ "</td>");
c++;
}
}
document.write("</tr>");
}
document.write("</table>");
}
</script>
</html>
你最好從頭開始你的代碼,而無需['文件。write()'](https://developer.mozilla.org/en-US/docs/Web/API/document.write)s; )。 – Teemu
如果你的老師推薦'font'標籤和/或'document.write',那麼他是一個欺詐行爲。不要再聽任何事情。 – m59