html onclick用于字典模式实现

时间:2016-01-23 13:20:27

标签: php html

Html新手在这里..

我正在尝试实现一个网页,弹出一些选定技术词汇的含义,如下所示。我有一个单词列表,其含义以csv格式提供。如何从列表中自动选择可用单词列表的含义?

<!DOCTYPE html>
<html>
<head>
<style>
.dropbtn {

}

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

.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-content a:hover {background-color: #f1f1f1}

.show {display:block;}
</style>
</head>
<body>

<h2></h2>
<p>Hands-On with <div class="dropdown">
<button id="myBtn" class="dropbtn">Ultrahaptics'</button>
  <div id="myDropdown" class="dropdown-content">
    <a href="#home">Feel of touch without wearing devices</a>

  </div>
</div>
 gave us a feel of technology of future.
</p>

<script>
// Get the button, and when the user clicks on it, execute myFunction
document.getElementById("myBtn").onclick = function() {myFunction()};

/* myFunction toggles between adding and removing the show class, which is used to hide and show the dropdown content */
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');
      }
    }
  }
}
</script>

</body>
</html>

PS:像

这样的事情
<a title="Feel of touch without wearing devices">Ultrahaptics'</a> 

仅适用于鼠标指针,不适用于触摸设备。因此,寻找适用于触摸设备的解决方案。

2 个答案:

答案 0 :(得分:0)

我可以看到你使用的是javascript。我建议使用jQuery-CSV

这可以帮助您使用javascript阅读您的csv。您可以访问此链接,因为这与您的问题有些相关。 Evans Answer

答案 1 :(得分:-1)

使用jQuery,这将是一个简单的例子:

$('.dropbtn').click(function(){
    $(this).siblings('.dropdown-content').toggleClass('hide');
});

使用以下CSS:

.dropdown-content{
  position:absolute;
  background:#000;
  color:#fff;
}
.hide{
  display:none;
}

我已经简化了您的HTML:

<p>
  Hands-On with
  <span class="dropdown">
    <button type="button" class="dropbtn">Ultrahaptics'</button>
    <a href="#home" class="dropdown-content hide">Feel of touch without wearing devices</a>
  </span>
  gave us a feel of technology of future.
</p>

您可以在此处看到它:https://jsfiddle.net/a73t8L4m/

您可能也有兴趣使用the dfn tag,但这会让您的HTML看起来有点不同。