English 中文(简体)
在隐藏的输入类型中显示 javascamp 数组值
原标题:Show javascript array value in input type hidden

我有一个关于Javascript阵列的问题

我有以下射手阵列:

var startTimeList= new Array();

我在其中输入了一些值。 现在我有以下输入( 隐藏类型) :

 <input type="hidden" value"startTimeList[0]" name="startTime1" />

Hoewever, 这显然不正确, 因为输入隐藏类型中无法识别 javascript 数组 。 所以我甚至无法获得一个值 。

有谁知道我如何从一个射手阵列获得输入类型中的值吗?

问题回答

您需要将值设置为 Javascript :

document.getElementById(...).value = startTimeList[0];

使用此选项 :

<script>
window.onload = function() {
    document.getElementsByName("startTime1")[0].value = startTimeList[0];
}
</script>

You have to set value from javascript. Something like document.getElementById (ID).value = startTimeList[0];

您从 body oload 事件中执行 javascript 。

您需要通过 JavaScript 本身来设置值 。

document.getElementById("startTime1").value = startTimeList[0]; 

或 J 查询

$("#startTime1").val(startTimeList[0]);

将“ 启动时间 1” 指定为上面的代号 。

您可以在名称中找到元素 :

document.getElementsByName(name)[index].value =  new value ;

<强 > OR

您应该识别您的元素, 然后更改值 ;

  1. Give your element an ID for example id="ex"
  2. Get the element with JavaScript(of course once the DOM is ready) with var element = document.getElementById( ex )
  3. Change the value with element.value = your value ;

d 需要将数组分割成一个分隔的字符串,然后将该字符串指定为隐藏输入值。

然后,在后退或类似的事件上,您要将数值分析回到一个数组,以便在 JavaScript 中使用:

var startTimeList = [1,2,3,4,5];
var splitList =   ;
for(var i = 0;  i < startTimeList.length; i++)
{
    splitList += startTimeList[i] +  | ;
}

并重覆 :

var splitList =  2|4|6|8| ;
var startTimeList = splitList.split( | );




相关问题
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.

热门标签