将数据保存在javascript数组中

时间:2012-11-26 00:59:29

标签: javascript jquery

每次按下按钮时,我都需要使用javascript填充数组。

例如:如果数组是{[10,2,5]},我又点击了按钮,它应该是{[10,2,5],[6,3,4]}

问:这可以吗?你能给我一个起点吗?

$('#button').click(function()     {
//populating array keeping old data everytime user push button.
}

<form id="myForm">
    //data that ill go to array
    <input type="button" id="button" value="ok">
</form>

1 个答案:

答案 0 :(得分:3)

var myArray = [];

$('#button').click(function(){
  var newArray = [];
  myArray.push(newArray);
});