javascript - How to make the search box of the navigation website automatically obtain the input cursor focus?
PHP中文网
PHP中文网 2017-06-12 09:28:26
0
2
823

For example, this navigation website: https://www.2345.com/
After opening, the cursor did not automatically locate the Baidu search box.
I tried to get the id and call the focus function but it didn’t work.
How to write a piece of js code to automatically get focus every time you open this website?
The effect is like https://www.hao123.com/

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(2)
洪涛

focus() should be fine, just write something like:

<input id="t1" type="text" value="abc"><br>
<input id="t2" type="text" value="def"><br>
<script>
    t2.focus();
</script>

Can you post the code for a look?

代言

Write the autofocus attribute directly on the input tag. Is it the onfocus() method in js?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template