js如何给表单赋值
<formname="stuinfo"id="stuinfo"method="post"><selectid="year"></select><selectid="mon...
<form name="stuinfo" id="stuinfo" method="post">
<select id="year">
</select>
<select id="month" onchange="datealter(this.value)">
</select>
<select id="day">
</select>
<br />
<input type="submit" name="submit"/>
<input type="reset" />
</form>
<script>
function datealter(d){
var select_year=document.getElementById("year");
for(var i=0; i<=2014-1970;i++){
select_year.options[i]=new option(1970+i,1970+i);
}
var select_month = document.getElementById("month");
var select_day = document.getElementById("day");
select_day.options.length = 0;
for(var i=0;i<endday;i++)
select_day.options[i] = new Option(i+1,i+1);
for(var i=0;i<12;i++)
select_month.options[i] = new Option(i+1,i+1);
var endday=1;
if(d==1||d==3||d==5||d==7||d==8||d==10||d==12){
endday=31;
}
if(d==4||d==6||d==9||d==11){
endday==30;
}
if(d==2){
var year=document.getElementById("year").value;
if((year%4==0&&year%100!==0)&&year&400==0){
endday=29;
}else
endday=28;
}
}
datealter(1);
</script>
错在哪里? 展开
<select id="year">
</select>
<select id="month" onchange="datealter(this.value)">
</select>
<select id="day">
</select>
<br />
<input type="submit" name="submit"/>
<input type="reset" />
</form>
<script>
function datealter(d){
var select_year=document.getElementById("year");
for(var i=0; i<=2014-1970;i++){
select_year.options[i]=new option(1970+i,1970+i);
}
var select_month = document.getElementById("month");
var select_day = document.getElementById("day");
select_day.options.length = 0;
for(var i=0;i<endday;i++)
select_day.options[i] = new Option(i+1,i+1);
for(var i=0;i<12;i++)
select_month.options[i] = new Option(i+1,i+1);
var endday=1;
if(d==1||d==3||d==5||d==7||d==8||d==10||d==12){
endday=31;
}
if(d==4||d==6||d==9||d==11){
endday==30;
}
if(d==2){
var year=document.getElementById("year").value;
if((year%4==0&&year%100!==0)&&year&400==0){
endday=29;
}else
endday=28;
}
}
datealter(1);
</script>
错在哪里? 展开
3个回答
展开全部
提问者是在出题目考我们吧
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>test</title>
<script type="text/javascript">
function datealter(d, isFirst) {
var select_year = document.getElementById("year");
var select_month = document.getElementById("month");
var select_day = document.getElementById("day");
if (!!isFirst) {
for (var i = 0; i <= 2014 - 1970; i++) {
var option = new Option(1970 + i, 1970 + i) || document.createElement("option");
option.value = 1970 + i;
option.innerHTML = 1970 + i;
select_year.appendChild(option);
}
for (var i = 0; i < 12; i++) {
var option = new Option(i + 1, i + 1) || document.createElement("option");
option.value = 1 + i;
option.innerHTML = 1 + i;
select_month.appendChild(option);
}
}
var endday = 1;
if (d == 1 || d == 3 || d == 5 || d == 7 || d == 8 || d == 10 || d == 12) {
endday = 31;
}
else if (d == 4 || d == 6 || d == 9 || d == 11) {
endday = 30;
}
else if (d == 2) {
var year = select_year.value;
if ((year % 4 == 0 && year % 100 !== 0) && year & 400 == 0) {
endday = 29;
} else {
endday = 28;
}
}
select_day.options.length = 0;
for (var i = 0; i < endday; i++) {
var option = new Option(i + 1, i + 1) || document.createElement("option");
option.value = 1 + i;
option.innerHTML = 1 + i;
select_day.appendChild(option);
}
}
window.onload = function() {
datealter(1, 1);
}
</script>
</head>
<body>
<form name="stuinfo" id="stuinfo" method="post">
<select id="year">
</select>
<select id="month" onchange="datealter(this.value)">
</select>
<select id="day">
</select>
<br />
<input type="submit" name="submit"/>
<input type="reset" />
</form>
</body>
</html>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
根据元素name属性或者 id属性查找到对应元素 然后对value属性进行赋值
举个例子: 要对 <input type='text' id='userName'name='userName' /> 的文本框赋值
document.getElementById("userName").value='张三';
这样就可以了
举个例子: 要对 <input type='text' id='userName'name='userName' /> 的文本框赋值
document.getElementById("userName").value='张三';
这样就可以了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询