如何从日历javascript-HTML5中获取日期、月份、年份值
我有一个日历,当我选择一个日期时,我想从javascript中通过一些值进行检查,我选择这些值来告诉我它是否正确 这是我的密码:如何从日历javascript-HTML5中获取日期、月份、年份值,javascript,html,Javascript,Html,我有一个日历,当我选择一个日期时,我想从javascript中通过一些值进行检查,我选择这些值来告诉我它是否正确 这是我的密码: <!DOCTYPE html> <html lang="en"> <meta charset="UTF-8"> <head> <title>SOMETHING</title> <script> function check(){ if (do
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<head>
<title>SOMETHING</title>
<script>
function check(){
if (document.getElementById("cinema").value == "1"){
var d = new date();
var x = document.getElementById("date");
x.innerHTML=d.getMonth();
if (x == "1"){
document.write("ok");
}
}
else {
alert('null');
}
}
</script>
</head>
<body>
<header>
<h1>SOMETHING</h1>
</header>
<br />
<div>
<form>
<fieldset>
<label for="date">CHECK DATE</label>
<input type="date" id="date" name="date" required="required"/>
<br />
<label for="time">CHECK TIME</label>
<input type="time" id="time" name="time" required="required" />
</fieldset>
</form>
</div>
<br />
<button onclick='check()'>Check</button>
</body>
</html>
某物
函数检查(){
if(document.getElementById(“电影院”).value==“1”){
var d=新日期();
var x=document.getElementById(“日期”);
x、 innerHTML=d.getMonth();
如果(x=“1”){
文件。填写(“确定”);
}
}
否则{
警报(“空”);
}
}
某物
核对日期
检查时间
检查
您需要首先为date对象指定一个值,然后从中导出day、month和year
var d = new date(document.getElementById("date"));
alert(d.getMonth())
以下是一些应该让你走上正轨的东西:
function check()
{
var Temp= document.getElementById("date");
var myDate = new Date(Temp.value);
document.write(myDate);
document.write("<br />");
document.write(myDate.getMonth());
}
函数检查()
{
var Temp=document.getElementById(“日期”);
var myDate=新日期(临时值);
文件编写(myDate);
文件。写(“
”);
document.write(myDate.getMonth());
}
就是这样
函数检查(){
var a=document.getElementById(“thedate”).value;
var check=“2013-01-20”;
如果(a==检查){
警惕(“是”);
}否则{
警报(“停止”);
}
}
试试看
您忘了发布Javascript。这里的人会帮你,但不会为你写代码。对不起,史蒂夫,这是我的错,我错过了…你犯了什么错误?什么都不做。。。此外,我无法理解这样做的区别:var fordate=document.getElementByID(“date”).value;警报('fordate');}除此之外:var d=新日期(document.getElementById(“日期”);警报(d.getMonth());myDate.getFullYear()返回我2013年的myDate.getDate()返回我的日期,但myDate.getMonth()返回0。。。但正如你所说,我现在已经走上正轨了!谢谢现在的问题是如何将它与我保存过一次的日期进行比较……如果用户输入2013年1月20日会怎么样?