好的,我又来了。对于那些没有看到我最后一个问题的人,我正在设计一个HTML数据采集系统。我已经写了一堆代码,它的基本概念是单击按钮以增加隐藏的计数器,然后最后以可以轻松地将其添加到.csv文件的方式打印一堆变量。除导出部分外,它的运行异常出色。当我打印出来时,它只会显示
[对象对象],[对象对象],[对象对象],[对象对象],[对象对象]
当我需要它显示时
variableoutput1,variableoutput2,variableoutput3,variableoutput4,variableoutput5,
当前代码如下:
<script src="script.js"></script>
<script type="text/javascript">
var Match = prompt("What is the match number? type numbers only");
var Team = prompt("Which team are you scouting? type numbers only");
</script>
<!-- this is the script to copy and paste for each button-->
<script type="text/javascript">
var BUTTON1 = 0;
</script>
<script type="text/javascript">
var BUTTON2 = 0;
</script>
<script type="text/javascript">
var BUTTON3 = 0;
</script>
<button onclick="BUTTON1++">Increment1</button>
<button onclick="BUTTON2++">Increment2</button>
<button onclick="BUTTON3++">Increment3</button>
<script type="text/javascript">
var stockData = [
{Team},
{Match},
{BUTTON1},
{BUTTON2},
{BUTTON3},
];
</script>
<button onclick="document.write(stockData)">Export</button>
感谢任何能提供帮助的人
答案 0 :(得分:0)
首先,您不需要多个脚本标签,只能使用1个脚本标签;其次,{}
会将值视为对象。因此,将其删除并仅用作变量
var Match = prompt("What is the match number? type numbers only");
var Team = prompt("Which team are you scouting? type numbers only");
var BUTTON1 = 0;
var BUTTON2 = 0;
var BUTTON3 = 0;
var stockData = [Team, Match, BUTTON1, BUTTON2, BUTTON3];
<button onclick="BUTTON1++">Increment1</button>
<button onclick="BUTTON2++">Increment2</button>
<button onclick="BUTTON3++">Increment3</button>
<button onclick="document.write(stockData)">Export</button>