我定义了函数'myFunction(a,b)',并尝试使用它来转换xml文件中的值以创建新变量'b',然后将其写入表中。但是,myFunction或document.write(b [i])不起作用。知道我做错了什么吗?
<script type="text/javascript">
//<![CDATA[
<!-- Request DATA -->
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","http://datapoint.metoffice.gov.uk/public/data/val/wxfcs/all/xml/352438?res=3hourly&key=[value],false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
<!-- Write Table header -->
var tableHeaders = ["Time", "Temp"];
document.write("<table><tr>");
for (i=0; i<tableHeaders.length;i++)
{
document.write("<th>");
document.write(tableHeaders[i].bold() + "   ");
document.write("<\/th>");
;
}document.write("<\/tr>");
<!-- Write DATA -->
var x=xmlDoc.getElementsByTagName("Rep");
for (i=0;i<2;i++)
{
var b[i] = myFunction(x[i].childNodes[0].nodeValue, 0.001); //<--- NOT WORKING
document.write("<tr><td>" +b[i] + "<\/td>"); //<---NOT WORKING
//document.write("<tr><td>" +x[i].childNodes[0].nodeValue + "<\/td>");
document.write("<td>" + x[i].getAttribute("T") +"°C"+"<\/td>"); //temp
document.write("<\/tr>");
} document.write("<\/table>");
</script>function defining <script type="text/javascript">
//<![CDATA[
function myFunction(a, b) {
return a * b;
};
//]]>
</script>
答案 0 :(得分:1)
myFunction
。稍早移动你的myFunction声明。