url ?>-6ren">
gpt4 book ai didi

javascript - 单击 div 类 a href 按钮时如何聚焦于输入元素

转载 作者:行者123 更新时间:2023-12-02 22:20:21 24 4
gpt4 key购买 nike

 <ul id="top_menu">
<li>
<a href="#" id="arabutton" class="search-overlay-menu-btn" ><?php echo $pages->get('/')->text36;?></a>
</li>
</ul>



<!-- Search Menu -->
<div class="search-overlay-menu">

<form id="form-game_v2" name="form-game_v2" method="get" action="<?php $pages->get("template=home")->url ?>" >
<div class="typeahead__container">
<div class="typeahead__field">
<div class="typeahead__query">
<input class="js-typeahead-game_v2" id="ara" name="form" type="search" placeholder="Search" autofocus>
</div>
<div class="typeahead__button">
<button type="submit">
<i class="typeahead__search-icon"></i>
</button>
</div>
</div>
</div>
</form>
</div><!-- End Search Menu -->

我需要关注输入 id="ara"当点击 id="arabutton"

我怎样才能做到这一点?它是一个实时搜索系统。当单击按钮时,会出现类型覆盖输入字段。

实例:http://medilocation.com/en/treatments/pediatric-cardiology/单击右上角进行搜索,您会看到焦点问题。

最佳答案

您应该使用 JavaScript:

document.addEventListener('DOMContentLoaded', () => {
const input = document.getElementById('ara');
const button = document.getElementById('arabutton');

button.addEventListener('click', () => {
input.focus();
})
})

关于javascript - 单击 div 类 a href 按钮时如何聚焦于输入元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59250178/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com