我应该创建一个表格,用户将输入其数据。 所以我们有产品名称和价格和计数作为我们的专栏。如何更改表格中只有一行的颜色(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