怎样在 .aspx里添加这个年月日的东西??
我想在页面里加个日期的联动选择,但是如果把下面这个代码放在
<form id= "Form1 " method= "post " runat= "server "> 里,就提示js错误,请问应该怎么把年月日的这个东西放在页面里?后台怎么获取这个值,并保存进数据库??
<script language= "JavaScript ">
function newlist(obj,n,t)
{
obj.options.length = t-n+1;
for(var ii=n; ii <=t; ii++)
{
obj.options[ii-n].text = ii
obj.options[ii-n].value = ii
}
}
function lpc()
{
var y = sa.value;
var m = sb.value;
var d = new Date(y,m,0)
var k = d.getDate();
newlist(sc,1,k);
}
</script>
<select size= "1 " name= "sa " onchange= "lpc() " id= "sa "> </select> 年
<select size= "1 " name= "sb " onchange= "lpc() " id= "sb "> </select> 月
<select size= "1 " name= "sc " id= "sc "> </select> 日
<script language= "JavaScript ">
newlist(sa,1990,2010);
newlist(sb,1,12);
lpc();
</script>
------解决方案-------------------- <form id= "form1 " runat= "server ">
<script language= "JavaScript " type= "text/javascript ">
function newlist(obj,n,t)
{
obj.options.length = t-n+1;
for(var ii=n; ii <=t; ii++)
{
obj.options[ii-n].text = ii
obj.options[ii-n].value = ii
}
}
function lpc()
{
var y = document.getElementById( "sa ").value;
var m = document.getElementById( "sb ").value;
var d = new Date(y,m,0)
var k = d.getDate();
newlist(document.getElementById( "sc "),1,k);
}
</script>
<select size= "1 " name= "sa " onchange= "lpc() " id= "sa "> </select> 年
<select size= "1 " name= "sb " onchange= "lpc() " id= "sb "> </select> 月
<select size= "1 " name= "sc " id= "sc "> </select> 日
<script language= "JavaScript " type= "text/javascript ">
newlist(document.getElementById( "sa "),1990,2010);
newlist(document.getElementById( "sb "),1,12);
lpc();
</script>
</form>
------解决方案--------------------后台怎么获取值,并保存进数据库嘛,这样可以解决
在 <form id= "Form1 " method= "post " runat= "server "> 中加
<input type= "hidden " id= "hidden1 " runat= "server " />
<asp:Button ID= "Button1 " runat= "server " OnClick= "Button1_Click " Text= "Button " />
在后台的Page_Load事件中加
Button1.Attributes.Add( "onClick ", "javascript:document.getElementById( 'hidden1 ').value=document.getElementById( 'sa ').value; ");
在后台的Button1_Click事件中
Response.Write(hidden1.Value);
这样就可以输出“年”的值,其他月,日的值类似,怎么保存到数据库不用我说了吧
------解决方案--------------------