我想知道是否有办法将焦点放在本地input
之后的href
就像这里我所拥有的:
<a href="#bottom"> Sign up </a>
And at the bottom of the page :
<div id="bottom">
<input type="email" name="email" id="email" placeholder="email address">
</div>
我想要的是当有人在注册时出现问题时,它直接进入底部页面并将注意力集中在input
上,这样用户就可以直接输入他的电子邮件地址,而不必使用clic。
谢谢!
答案 0 :(得分:3)
使用label
样式a
。确保label
的{{1}}属性与for
的{{1}}属性相匹配。这会在点击input
时关注id
并滚动页面,以便查看input
。
label
input
答案 1 :(得分:1)
这应该可以解决问题:
已更新 HTML:在链接中添加了ID
<a id="signUpLink" href="#bottom"> Sign up </a>
And at the bottom of the page :
<div id="bottom">
<input type="email" name="email" id="email" placeholder="email address">
</div>
<强>的jQuery / JavaScript的强>
$(document).ready(function(){
var $link = $("#signUpLink");
var $emailInput = $("#email");
$link.on("click", function(){
$emailInput.focus();
});
});