如何使用javascript从输入类型=日期的html元素中获取所选日期

时间:2018-03-12 10:52:33

标签: javascript

<script>

function datechecker()
	{
      /* Here,How can i display selected date*/
	}
</script>
<!DOCTYPE html>
<html>
<head>
	<title></title>
</head>
<body>
		
<form method="POST" role="form" name="myform" enctype="multipart/form-data">
		<h2>Please select datey</h2>
		<input type="date" id="jsdate"  name="txtdate">
		<input type="submit" onclick="datechecker()" value="Check">
		</form>
</body>
</html>

在这里,我已经定义input type=date来选择日期....我想仅使用javascript 显示所选日期....我该怎么办?

1 个答案:

答案 0 :(得分:1)

&#13;
&#13;
function datechecker(){
/* Here,How can i display selected date*/
event.preventDefault(); // remove this line in your code.
console.log(jsdate.value);
}
&#13;
<!DOCTYPE html>
<html>
<head>
	<title></title>
</head>
<body>
		
<form method="POST" role="form" name="myform" enctype="multipart/form-data">
		<h2>Please select datey</h2>
		<input type="date" id="jsdate"  name="txtdate">
		<input type="submit" onclick="datechecker()" value="Check">


		</form>

</body>
</html>
&#13;
&#13;
&#13;