English 中文(简体)
Javascript: • 如何保存经常数据
原标题:Javascript: How to Keep Persistant Array Data
  • 时间:2010-08-01 00:45:38
  •  标签:
  • javascript

我试图用 j子建造一个阵列,其中包含一个女方名单。 这里是我所具备职能的简化版本。

function updateCost(id) {
    var inputArray = [];
    inputArray.push(id);
}

这里是《html法典》。

<input type="file" name="field1" id="field1" onchange="updateCost( 1 );" />
<input type="file" name="field2" id="field2" onchange="updateCost( 2 );" />
<input type="file" name="field3" id="field3" onchange="updateCost( 3 );" />
...

我所希望的是,每当我利用我拥有的一个档案输入领域从我的计算机中挑选一个文件时,我就希望把这一投入场的id放在投入阵列中。 然而,每当我选择一个档案时,它就补充了该阵列,但它却把它推到阵列上,因此,阵列中的其他一切都被删除,只留下一个阵列。

是否有办法使阵列数据具有持久性,以便在我使用档案输入领域之一时每增加一次数据?

感谢!

最佳回答
(function() {


   var inputArray = [];
   function updateCost(id) {
    inputArray.push(id);
   }


})();

将其界定为职能范围之外。 你实际上不需要在我个人风格的周围穿戴头巾。

问题回答
function updateCost(id) {
    if(typeof updateCost.inputArray=="undefined")updateCost.inputArray=[]
    updateCost.inputArray.push(id);
}

使阿雷拉成为“科学”





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签