简体   繁体   English

使用 javascript 使用谷歌日历检查日期和时间

[英]Check date and time with google calendar using javascript

I'm trying to let the user chooses certain date and time and check the calendar if we have any events interfering with the user inputs我试图让用户选择特定的日期和时间并检查日历是否有任何干扰用户输入的事件

<!DOCTYPE html>
<html>

<head>
<base target="_top">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato">

<style>
</style>

</head>

<body>

<div>From<input class="w3-input w3-border" type="datetime-local" id="from"></div>
<div>To<input class="w3-input w3-border" type="datetime-local" id="to"></div>
<button style="width:100%" class="w3-button w3-black w3-section" onclick="check()">check</button>
<div style="display:none" id="no">Not Available</div>
<div style="display:none" id="yes">Available</div>

<script>
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.getDefault());// 2018-06-19T22:38:28+0000
</script>

<script>
function check() {
var startTime = document.getElementById("from").innerHTML;
var endTime = document.getElementById("to").innerHTML;
var cal = CalendarApp.getCalendarById("aqsv50qhum57qbh7a581cft1o0@group.calendar.google.com");
var allEvents = cal.getEvents(new Date(startTime), new Date(endTime));
if (allEvents.length > 0) {
document.getElementById("no").style.display = "block";
}else {
document.getElementById("yes").style.display = "block";
}
}
</script>

</body>
</html>

I tried the above code but it returns nothing, thanks for helping我尝试了上面的代码,但它没有返回任何东西,感谢您的帮助

innerHTML is only for content WITHIN the brackets of the element. innerHTML 仅适用于元素括号内的内容。

For inputs you would need the value-property like this:对于输入,您需要像这样的值属性:

var inputValue = document.getElementById("myTextInputID").value;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM