日期:2014-05-18  浏览次数:20510 次

简单的问题,前台JS生成SELECT ,后台怎么获取它的值?

下面是JS,后台怎么获取?



<select id=year onchange=toDate()>
<script>for(i=1970;i<=2010;i++)document.write("<option>"+i+"</option>")</script>
</select>
<select id=month onchange=toDate()>
<script>for(i=1;i<=12;i++)document.write("<option>"+i+"</option>")</script>
</select>
<select id=day onchange=toDay()></select>
<input name=weekday>

<script>
var arr="日一二三四五六".split("")

function toDate(){
  with(document.all){
  vYear=parseInt(year.options[year.selectedIndex].text)
  vMonth=parseInt(month.options[month.selectedIndex].text)
  day.length=0;
  for(i=0;i<(new Date(vYear,vMonth,0)).getDate();i++){day.options[day.length++].value=day.length;day.options[day.length-1].text=day.length;}
  }
  toDay();
}

function toDay(){
  vDay=parseInt(document.all.day.options[document.all.day.selectedIndex].value)
  document.all("weekday").value="星期"+arr[new Date(vYear,vMonth-1,vDay).getDay()]
}

window.onload=toDate;
</script>

------解决方案--------------------
Request["xxxx"]
------解决方案--------------------
用javascript将生成的参数附加到url后面,如a.aspx?date=生成参数,或者将生成的参数放到一个form里面,再post到a.aspx,

a.apsx是处理生成的参数的页面,里面用request["date"]或request.form["date"]读取生成的参数
------解决方案--------------------
<select name=year id=year onchange=toDate() > 
<script >for(i=1970;i <=2010;i++)document.write(" <option >"+i+" </option >") </script > 
</select > 
<select name=month id=month onchange=toDate() > 
<script >for(i=1;i <=12;i++)document.write(" <option >"+i+" </option >") </script > 
</select > 
<select name=day id=day onchange=toDay() > </select > 
-----------------------------------------------------
Request.Form["year"];
Request.Form["month"];
Request.Form["day"];
------解决方案--------------------
用url传值 或XMLHttpRequest异步提交等都是不错的方法.
------解决方案--------------------
第一种方法:把你select值在提交的时候用JS保存到隐藏域中,然后在后台取隐藏域的值。


第二种方法:给你的select加上name属性,比如:<select id=year onchange=toDate() name="year" >
然后在后台这样取值: Request.Form["year"]

------解决方案--------------------
<select name=year runat="server" id=year onchange=toDate() >
<script >for(i=1970;i <=2010;i++)document.write(" <option >"+i+" </option >") </script >
</select >
<select name=month runat="server" id=month onchange=toDate() >
<script >for(i=1;i <=12;i++)document.write(" <option >"+i+" </option >") </script >
</select >
<select name=day runat="server" id=day onchange=toDay() > </select >

_______aspx.cs______________
string year = year.value
string month = month.value
string day = day.value