嗨,我有一个表格,用户可以选择开始日期和结束日期.例如,当天数为3时,将生成3行日期.每个日期,日期和时段(上午/下午)将存储在隐藏字段中.因此,3天将生成名为date_1,day_1,period_1,date_2,day_2,period_2,date_3,day_3,period_3的隐藏字段.
问题是如何处理这种动态数量的表单输入?我需要将值传递给控制器,然后建模以存储到数据库中.这是主要的问题,因为表单输入是数字是动态的,我们需要将它传递给控制器函数.
有人能告诉我处理这个问题的正确方法吗?教程的链接将有所帮助谢谢:)
这是用于生成日期列表的代码,如下图所示
function test(){
var count = 0;
var date1 = $('#alternatestartdate').val();
var date2 = $('#alternateenddate').val();
var startDate = new Date(date1);
var endDate = new Date(date2);
var Weekday = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
while (startDate<=endDate)
{
var weekDay = startDate.getDay();
if (weekDay < 6 && weekDay > 0) {
var month = startDate.getMonth()+1;
if( month <= 9 ) { month = "0"+month; }
var day = startDate.getDate();
var datearr = new Array();
if( day <= 9 ) { day = "0"+day; }
count++;
var datelist = day+"-"+month+"-"+startDate.getFullYear();
$('#pa').append(day+"-"+month+"-"+startDate.getFullYear() + " ("+Weekday[weekDay]+") FullHalf (AM)Half (PM)
");
}
startDate.setDate(startDate.getDate()+1)
}
$('#pa').append("");
}
如果正确插入,数据库中的数据将如下所示: