给< a>元素自动对焦 [英] Give <a> element autofocus
本文介绍了给< a>元素自动对焦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用以下代码,我试图在页面加载时为元素提供自动对焦.
With the following code I try to give an a element autofocus when the page is loaded.
<a href="/{{setting}}" id="next" class="button big active">Next vocabulary</a>
<script>
document.getElementbyId("next").focus();
</script>
虽然这在输入字段上可以正常使用,但不适用于该元素.有人可以解释一下我吗?
Whilst this works fine with input fields it doesn't work with that a element. Can anybody explain me while?
致谢
推荐答案
问题是您键入的getElementById
错误,应该是大写的'B'.
The problem is that you typed getElementById
wrong, it should be an uppercase 'B'.
<a href="/{{setting}}" id="next" class="button big active">Next vocabulary</a>
<script>
document.getElementById("next").focus();
</script>
现在应该可以了!
这篇关于给< a>元素自动对焦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文