下拉HTML文件下载

时间:2017-01-12 14:15:14

标签: javascript html css

我需要一个这样的下拉菜单:http://www.w3schools.com/howto/howto_js_dropdown.asp 但是使用提交按钮,按下即可下载所选文件。我希望有人能帮助我。

1 个答案:

答案 0 :(得分:0)

这个怎么样?插入你的链接,但也告诉我们你试图帮助你更多



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

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');
      }
    }
  }
}
&#13;
h2 { color: #111; font-family: 'Open Sans Condensed', sans-serif; font-size: 24px; font-weight: 70; line-height: 48px; margin: 0 0 24px; padding: 0 30px; text-align: center; text-transform: uppercase; }
p { color: #111; font-family: 'Open Sans', sans-serif; font-size: 16px; line-height: 28px; margin: 0 0 48px; }
.dropbtn {
    background-color:#51858c;
    color: white;
    padding: 16px;
    font-size: 16px;
    border: none;
    cursor: pointer;
}

.dropbtn:hover, .dropbtn:focus {
    background-color:#679196;
}

.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-content {
    display: none;
    position: absolute;
    background-color: #f9f9f9;
    min-width: 160px;
    overflow: auto;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}

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

.dropdown a:hover {background-color: #f1f1f1}

.show {display:block;}
&#13;
<h2>Clickable Download</h2>
<p>Click on the button to open the download list</p>

<div class="dropdown">
<button onclick="myFunction()" class="dropbtn">DOWNLOADS</button>
  <div id="myDropdown" class="dropdown-content">
    <a href="#home">ADD YOUR 1 LINK DOWNLOAD</a>
    <a href="#about">ADD YOUR 2 LINK DOWNLOA</a>
    <a href="#contact">ADD YOUR 3 LINK DOWNLOA</a>
  </div>
</div>
&#13;
&#13;
&#13;