我有一个非常简单的页面,它读取HTML表格中的XML文件。它适用于Chrome和FF,但不会在IE 11中加载表。我们的用户目前仍在Win7上。
在Chrome和FF中,如果值为> 3,则表格会显示甚至使背景颜色变为黄色。
当我将此代码输入此站点时,我发现了以下错误:
未捕获的SyntaxError:意外的令牌。
抱歉,我只是在学习java脚本,不知道如何解决这个问题。
非常感谢你寻找。
<script language="JavaScript">
document.write("<table>");
document.write("<tr>");
document.write("<th>Time</th>");
document.write("<th>Count</th>");
document.write("</tr>");
// Create a connection to the file.
var Connect = new XMLHttpRequest();
// Define which file to open and
// send the request.
Connect.open("GET", "WebSchCallCount.xml", false);
Connect.setRequestHeader("Content-Type", "text/xml");
Connect.send(null);
// Place the response in an XML document.
var TheDocument = Connect.responseXML;
// Place the root node in an element.
var PuTime = TheDocument.childNodes[0];
// Retrieve each PuTime in turn.
for (var i = 0; i < PuTime.children.length; i++)
{
var Calls = PuTime.children[i];
// Access each of the data values.
var count = Calls.getElementsByTagName("count");
var PickupTime = Calls.getElementsByTagName("PickupTime");
// Write the data to the page.
document.write("<tr><td>");
document.write(PickupTime[0].textContent.toString());
document.write("</td><td>");
document.write(count[0].textContent.toString());
document.write("</td></tr>");
}
var trTags = document.getElementsByTagName("tr");
for (var i = 0; i < trTags.length; i++) {
var tdSecondEl = trTags[i].children[1]; // starts with 0, so 3 is the 4th element
if (tdSecondEl.innerText > 3) {
tdSecondEl.style.backgroundColor = "yellow";
} else {tdSecondEl.style.backgroundColor = "";
}
}
</script>
<style>
h3 {font-family: arial, sans-serif;}
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 50px;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 6px;
data-monetary-amount^="2":after {color: red;}
}
tr:nth-child(even) {
background-color: #dddddd;
}
</style>
<table>
<tr><th>Time</th><th>Count</th></tr>
<tr><td>10:00:00</td><td>1</td></tr>
<tr><td>10:30:00</td><td>1</td></tr>
<tr><td>10:45:00</td><td>1</td></tr>
<tr><td>11:00:00</td><td>2</td></tr>
<tr><td>11:15:00</td><td>1</td></tr>
<tr><td>12:00:00</td><td>4</td></tr>
<tr><td>12:15:00</td><td>1</td></tr>
<tr><td>12:30:00</td><td>2</td></tr>
<tr><td>13:00:00</td><td>1</td></tr>
<tr><td>13:15:00</td><td>1</td></tr>
<tr><td>14:00:00</td><td>4</td></tr>
<tr><td>14:15:00</td><td>2</td></tr>
<tr><td>14:30:00</td><td>1</td></tr>
<tr><td>14:45:00</td><td>2</td></tr>
<tr><td>15:00:00</td><td>1</td></tr>
<tr><td>15:45:00</td><td>1</td></tr>
<tr><td>16:00:00</td><td>1</td></tr>
</table>
答案 0 :(得分:0)
因为代码在其他浏览器(iPhone / ipad)中运行,我会把它归咎于IE并继续我的生活。