从 onClick 传递值

passing values from onClick

给定以下代码,如何从 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>

这似乎是您正在做的事情,应该可以帮助您入门:

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  );
  }
}
<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>