Javascript 动态HTML选择器/选项未以表单形式发送
我的javascript代码中有几个选择器。其中一个是生成另一个选择器的触发器:Javascript 动态HTML选择器/选项未以表单形式发送,javascript,html,forms,Javascript,Html,Forms,我的javascript代码中有几个选择器。其中一个是生成另一个选择器的触发器: <form id="reportform" name="reportform" action=""> <table cellpadding="3" cellspacing="16"> <thead> <th class="report" colspan="2">Select Scope</th>
<form id="reportform" name="reportform" action="">
<table cellpadding="3" cellspacing="16">
<thead>
<th class="report" colspan="2">Select Scope</th>
<th class="report" colspan="2">Select Date</th>
<th class="report" colspan="2">Options</th>
</thead>
<tbody>
<tr>
...
<td>
Period
</td>
<td>
<select id="period" name="period">
<option selected="selected" value="0">- Select -</option>
<option value="1">Day</option>
<option value="2">Month</option>
<option value="3">Year</option>
</select>
</td>
...
</tr>
...
<tr>
<td></td>
<td></td>
<td id="date-label2"></td>
<td id="date2"></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td align="right">
<input id="go" class="go" type="submit" value="Report">
</td>
</tr>
</tbody>
</table>
</form>
此处使用的函数:
function clearDates(){
var date = document.getElementById("date-label");
while (date.hasChildNodes()) {
date.removeChild(date.lastChild);
}
date = document.getElementById("date");
while (date.hasChildNodes()) {
date.removeChild(date.lastChild);
}
date = document.getElementById("date-label2");
while (date.hasChildNodes()) {
date.removeChild(date.lastChild);
}
date = document.getElementById("date2");
while (date.hasChildNodes()) {
date.removeChild(date.lastChild);
}
}
关键是,当我单击submit按钮时,我看不到序列化的表单的动态元素,我想不会发送到服务器
$(function(){
$("#reportform").submit(function(event){
event.preventDefault();
alert(JSON.stringify($('form').serializeObject()));
return false;
});
});
表单是否可能获得这些动态字段?
提前感谢新创建的输入似乎没有“name”属性。完全正确。我通过添加
input.name=“day”解决了这个问题代码>。非常感谢。
$(function(){
$("#reportform").submit(function(event){
event.preventDefault();
alert(JSON.stringify($('form').serializeObject()));
return false;
});
});