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中文网2017-06-12 09:30:26
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?
代言2017-06-12 09:30:26
Write the autofocus attribute directly on the input tag. Is it the onfocus() method in js?