我希望我的代码显示 170, 122 。所有值都已在 Javascript 中设置,但我仍然没有得到输出。
<!DOCTYPE html>
<html>
<body>
<button onclick="UidToPost()">Get It</button>
<script>
var SetUid1 = "170";
var SetUid2 = "122";
var SetUid3 = "135";
var SetUid4 = "144";
var c = 0;
var timingToSend;
var SetUid;
function UidToPost() {
c = c + 1;
var postTo = "SetUid" + c + "";
document.getElementById("do").innerHTML = postTo;
timingToSend = setTimeout('UidToPost()', 1000);
};
</script>
<p id="do"></p>
</body>
</html>
提前致谢。
这是我正在使用的代码
var SetUid = [ "170", "122", "135", "144" ];
var c = 0;
var timingToSend;
function UidToPost() {
var postTo = SetUid[c++];
document.getElementById("do").innerHTML = postTo;
if (c < SetUid.length)
timingToSend = setTimeout(UidToPost, 1000);
};