我是Javascript的新手并且正在处理一个问题,它是关于建立一个允许用户输入项目出价以及出价ID的网站。当他们同时输入时,按下提交按钮,出价/出价ID(以及日期和时间)将显示在文本区域中。
应该允许提交并显示多个出价,但目前我只能显示一个出价。任何有关我如何能够显示多个出价的帮助将不胜感激。谢谢
var bids = new Array();
var bidders = new Array();
var bidTime = new Array();
function writeBid() {
var historyText = " ";
for (var i = 0; i < bids.length; i++) {
historyText = bidTime[i] + " " + bids[i] + " " + bidders[i] + "\n";
document.bidForm.bidList.value = historyText;
document.bidForm.highBid.value = bids[i];
document.bidForm.bidId.value = " ";
document.bidForm.bidAmount.value = " ";
}
}
function addBid() {
bidders.unshift(document.bidForm.bidId.value);
bids.unshift(document.bidForm.bidAmount.value);
var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds();
var timeText = hours + ":" + minutes + ":" + seconds;
bidTime.unshift(timeText);
writeBid();
}
function removeBid() {
bids.shift();
bidders.shift();
bidTime.shift();
writeBid();
}
答案 0 :(得分:1)
正如@nnnnnn所说,使用^[^{]{3}
和你的文本变量完美无缺:
<强>的JavaScript 强>
+=
<强> HTML 强>
var bids = [10, 20, 30];
var bidders = ['tim', 'sam', 'john'];
var bidTime = ['10/2/2013','12/5/213','14/1/2023'];
function writeBid() {
var historyText = " ";
for (var i = 0; i < bids.length; i++) {
historyText += bidTime[i] + " " + bids[i] + " " + bidders[i] + "\n";
document.bidForm.highBid.value = bids[i];
document.bidForm.bidId.value = " ";
document.bidForm.bidAmount.value = " ";
}
document.bidForm.bidList.value = historyText;
}