我正在进行HTML表单输入,用户可以在其中添加输入字段。
HTML代码如下
<form name="calculate" onSubmit="return submitForm(this.form)">
<fieldset>
<legend> calculate time </legend>
perform by: <input type="text" name="perform" id="perform" value=""/><br/><br/>
<div id="newlink">
<div>
<table border=0>
<tr>
<td> Date: </td>
<td> Start Time: </td>
<td> Stop Time: </td>
</tr>
<tr>
<td> <input type="date" name="Pdate[]" id="Pdate[]" value=""/></td>
<td> <input type="time" name="Stime[]" id="Stime[]" value=""/></td>
<td><input type="time" name="Etime[]" id="Etime[]" value=""/></td>
</tr>
</table>
<br/>
</div>
</div>
<p id="addnew">
<a href="javascript:new_link()"><input type="button" name="Add New" value="Add New"/></a>
</p>
<!-- Template for add on after 'Add new' button is click -->
<div id="addnewfield" style="display:none">
<div>
<table border=0>
<tr>
<td> <input type="date" name="Pdate[]" id="Pdate[]" value=""/></td>
<td> <input type="time" name="Stime[]" id="Stime[]" value=""/></td>
<td><input type="time" name="Etime[]" id="Etime[]" value=""/></td>
</tr>
</table>
</div>
</div>
</fieldset>
</form>
我试图调用表单来获取数组值,但该值似乎没有在
中解析脚本代码如下(所有脚本和html代码都在一个.html文件中
var pdate, startTime, endTime, totalTime;
<script>
function submitForm(frm){
var e = document.getElementsByTagName('input');
var a, s = 0;
for (a =0; a < e.length; a++){
if (e[i].type== "time" && e[i].name== "Stime[]"){
s++;
}
alert (s);
}
/*
startTime = document.getElementById['Stime[]'];
endTime = frm.elements['Etime[]'];
alert(startTime[0].value);
if (! startTime.length) {
alert (startTime.value + "<br/>" + endTime.value);
}
for (var i = 0; i<startTime.length; i++){
alert ( startTime[i].value + "<br/>" + endTime[i].value);
}
return true;*/
}
所有这些,仍然没有弹出警告信息。
提前感谢您的帮助