0
我有一个像this下拉菜单:可点击HTML下拉菜单
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>
我的问题是:我怎么能抓住一个标签的名字时,它的点击? 例如:我点击了#关于标签,我想searchBtn的名字成为关于。我怎样才能做到这一点 ?
怎么样加上'event'触发事件为'addEventListener'委派的元素?看起来像 - 'document.getElementById(“example”)。addEventListener(“click”,function(event){console.log(event.target)})',并从目标参数中获取href。 – YoroDiallo
你的html中的'#searchBtn'在哪里? – sol