[英]Clickable HTML Dropdown menu
i have dropdown menu like this : 我有一个下拉菜单此 :
document.getElementById("example").addEventListener("click", denemeFunc); function denemeFunc() { document.getElementById("searchBtn").innerText = ? ? ? ? ? ? ? ? ? ? ? ? ? ? }
<div class="dropdown"> <input type="text" placeholder="Search.." id="myInput" onkeyup="filterFunction()"> <div id="example" runat="server"> <a href="#About" data-toggle="About">About</a> <a href="#base" data-toggle="Base">Base</a> <a href="#blog" data-toggle="Blog">Blog</a> <a href="#contact" data-toggle="Contact">Contact</a> <a href="#custom">Custom</a> <a href="#support">Support</a> <a href="#tools">Tools</a> </div>
Here's my question : How can i catch the a tag's name when its clicked ? 这是我的问题:单击标签时如何捕捉标签的名称? For example : I clicked the #About tag and i want to searchBtn's name become the About.
例如:我单击#About标记,我要searchBtn的名称成为About。 How can i do this ?
我怎样才能做到这一点 ?
First receive the event object in the callback 首先在回调中接收事件对象
function denemeFunc(evt) {
Then you can interrogate the delegated element that fired the event via evt.target
然后,您可以通过
evt.target
询问触发事件的委托元素
document.getElementById("searchBtn").innerText = evt.target.innerHTML;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.