鉴于以下代码,如何从onCLick表单传递日,月和年的值以在脚本中生成变量$ date?
<head>
<!--
/* Generate day name script */
$date = "day. .month. .year";
function inDate() {
s = $date;
if (s != "" && s != null) determineDay(s);
alert ("Name date is "+$wDay+);
}
//-->
</head>
<body>
<input type="text" value="day" id="day" />
<input type="text" value="month" id="month" />
<input type="text" value="year" id="year" />
<form name='f1'><input value='Generate Day name' onclick='inDate()' type='button'></form>
</body>
答案 0 :(得分:0)
这似乎就是你正在做的事情,应该可以帮助你开始:
var date, wDay; //global vars
function determineDay(date){
// set global var wDay
wDay = [ 'Sunday', 'Monday', 'Tuesday', 'Wednesday'
, 'Thursday', 'Friday', 'Saturday'
][ date.getUTCDay() ];
}
function inDate(){
// Set global var date
date = new Date( Date.UTC( +document.getElementById('year').value
, document.getElementById('month').value -1 //month is zero-based
, +document.getElementById('day').value
)
);
if( !isNaN(date) ){ // test for invalid date
determineDay(date);
alert( 'Name date is ' + wDay );
}
}
&#13;
<input type="text" value="day" id="day" />
<input type="text" value="month" id="month" />
<input type="text" value="year" id="year" />
<form name="f1"><input value="Generate Day name" onclick="inDate()" type="button"></form>
&#13;