程序每秒钟产生一个随机数,同时用曲线图把随机数表示出来,为什么后面的时候程序一次表示了多个随机数,而不是一个随机数
SVG文件代码:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-flat-20030114.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100%" height="100%" onload="changeTemp()">
<script type="text/javascript" xlink:href="test.js"></script><g id="group"> <rect id="rect1" x="40" y="35" width="50" height="20" style="fill:red"></rect>
<text id="txt" x="50" y="50">1</text></g>
</svg>test.js代码:
var x1 = -10;
var y1 = 100;
var x2;
var y2;
var i = 1;
var temperature;
function changeTemp(){
var node=document.getElementById("txt");
temperature=Math.random();
temperature=temperature.toFixed(2);
node.firstChild.nodeValue=temperature; x2 = i*"10";
y2 = temperature*"100"; group=document.getElementById("group");
node2 = document.createElement("line"); node2.setAttribute("x1", x1);
node2.setAttribute("y1", y1);
node2.setAttribute("x2", x2);
node2.setAttribute("y2", y2);
node2.setAttribute("style", "fill:red");
group.appendChild(node2); x1 = x2;
y1 = y2; setInterval("changeTemp()",1000);
i = i+1;
}
SVG文件代码:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-flat-20030114.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100%" height="100%" onload="changeTemp()">
<script type="text/javascript" xlink:href="test.js"></script><g id="group"> <rect id="rect1" x="40" y="35" width="50" height="20" style="fill:red"></rect>
<text id="txt" x="50" y="50">1</text></g>
</svg>test.js代码:
var x1 = -10;
var y1 = 100;
var x2;
var y2;
var i = 1;
var temperature;
function changeTemp(){
var node=document.getElementById("txt");
temperature=Math.random();
temperature=temperature.toFixed(2);
node.firstChild.nodeValue=temperature; x2 = i*"10";
y2 = temperature*"100"; group=document.getElementById("group");
node2 = document.createElement("line"); node2.setAttribute("x1", x1);
node2.setAttribute("y1", y1);
node2.setAttribute("x2", x2);
node2.setAttribute("y2", y2);
node2.setAttribute("style", "fill:red");
group.appendChild(node2); x1 = x2;
y1 = y2; setInterval("changeTemp()",1000);
i = i+1;
}
然后把changeTemp中的setInterval("changeTemp()",1000); 去掉