添加到日历按钮/链接

时间:2018-07-24 13:07:05

标签: html calendar

我正在尝试创建“添加到日历”链接/按钮。当我单击按钮/链接时,它将为我提供Google日历/ outlook日历/ yahoo日历等选项。这是我要在文件中添加的一个片段。 enter image description here

我从https://www.addevent.com/那里得到了

有人对此有想法吗?谢谢!

1 个答案:

答案 0 :(得分:3)

function myFunction() {
    document.getElementById("myDropdown").classList.toggle("show");
}

// Close the dropdown if the user clicks outside of it
window.onclick = function(event) {
  if (!event.target.matches('.dropbtn')) {

    var dropdowns = document.getElementsByClassName("dropdown-content");
    var i;
    for (i = 0; i < dropdowns.length; i++) {
      var openDropdown = dropdowns[i];
      if (openDropdown.classList.contains('show')) {
        openDropdown.classList.remove('show');
      }
    }
  }
}
.dropbtn {
    background-color: white;
    border: 1px solid #777;
    color: #4c4c4c;
    padding: 16px;
    font-size: 16px;
    cursor: pointer;
}

.dropdown {
    position: relative;
    display: inline-block;
}
.dropdown-content {
    display: none;
    position: absolute;
    background-color: #fff;
    border: 1px solid lightgray;
    min-width: 200px;
    overflow: auto;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
    z-index: 1;
}

.dropdown-content a {
    color: black;
    padding: 12px 16px;
    text-decoration: none;
    display: block;
    color:#4c4c4c;
}

.dropdown a:hover {background-color: #ddd;}

.show {display: block;}
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">

<div class="dropdown">
<button onclick="myFunction()" class="dropbtn"> <i class="fa fa-calendar-o" aria-hidden="true"></i> Add to Calendar</button>
  <div id="myDropdown" class="dropdown-content">
    <a href="#"> <i class="fa fa-apple" aria-hidden="true"></i> Apple calendar</a>
    <a href="#"> <i class="fa fa-google" aria-hidden="true"></i> Google</a>
    <a href="#"> <i class="fa fa-windows" aria-hidden="true"></i> Outlook</a>
    <a href="#"><i class="fa fa-yahoo" aria-hidden="true"></i> Yahoo</a>
  </div>
</div>