Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/429.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 闰年事件处理_Javascript - Fatal编程技术网

Javascript 闰年事件处理

Javascript 闰年事件处理,javascript,Javascript,对于javascript,问题是 用户应在“输入年份”文本字段中输入年份。如果输入的数字是闰年,闰年文本字段应显示“是”,如果不是,则显示“否”。我必须使用按键事件处理程序 这是我使用的javascript,这个javascript不起作用 function myFunction() ("Enter A Year"); if x = (year % 100 === 0) ? (year % 400 === 0) : (year % 4 === 0); if(x){ ("This Is

对于javascript,问题是 用户应在“输入年份”文本字段中输入年份。如果输入的数字是闰年,闰年文本字段应显示“是”,如果不是,则显示“否”。我必须使用按键事件处理程序

这是我使用的javascript,这个javascript不起作用

function myFunction()
("Enter A Year");
if  x = (year % 100 === 0) ? (year % 400 === 0) : (year % 4 === 0);    
if(x){
 ("This Is A Leap Year");
  document.getElementById("x")
  }else{
   function myFunction ()
 ("This Is Not A Leap Year");
 document.getElementById("z")
 }
 }
这就是我使用的html

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Leap Year</title>
<script src="worksheet7.js" type="text/javascript" defer></script>
</head>
<body>
<h1>Leap Years</h1>
<input id="x" onkeyup="myFunction()"> Enter Year
<input id="z" onkeyup="myFunction()"> is it a leap year?

</body>
</html>

闰年
闰年
进入年份
这是闰年吗?

使用以下功能测试闰年:

function leapYear(year) {
  if (year % 400 === 0) {
    alert("It is a leap year");
  } else if (year % 100 === 0) {
    alert("It is not a leap year");
  } else if (year % 4 === 0) {
    alert("It is a leap year");
  } else {
    alert("It is not a leap year");
  }
}

jsfdle:

您有许多语法错误。因此,您需要回顾一些关于基本javascript的教程。然而,这段代码应该是您所追求的

document.getElementById(“x”).onkeyup=function(){
var year=parseInt(此.value);
变量isLeapYear=((第%4年==0)和&(第%100年!=0))| |(第%400年==0);
document.getElementById(“z”).value=isLeapYear?“是”:“否”;
}
闰年
进入年份


这是闰年吗?
你需要看一些关于基本javascript的教程:定义变量、函数、调用函数等。@vazed你的函数有太多语法错误。