admin管理员组文章数量:1287515
I have this clickable link,
`<a href="#" id="link">Clickable Link</a>`
and I have this <input>
which will e out after the link is clicked,
<input id="geo_title" type="text" value="some value" class="geo_title" />
in my script,
$('#link').click(function(){
$('input#geo_title').removeAttr('value');
$("input#geo_title").focus();
});
but sadly this does not focus the <input>
element. What I wanted was that, after I click the link, I don't have to click the <input>
element to be able to input something. What did I miss? Your help is highly appreciated. Thanks.
I have this clickable link,
`<a href="#" id="link">Clickable Link</a>`
and I have this <input>
which will e out after the link is clicked,
<input id="geo_title" type="text" value="some value" class="geo_title" />
in my script,
$('#link').click(function(){
$('input#geo_title').removeAttr('value');
$("input#geo_title").focus();
});
but sadly this does not focus the <input>
element. What I wanted was that, after I click the link, I don't have to click the <input>
element to be able to input something. What did I miss? Your help is highly appreciated. Thanks.
- 1 It's working in Chrome, see jsfiddle/ZgQPk In which browser do you have issues? – koopajah Commented Feb 8, 2013 at 15:22
- Also working in firefox, be more precise... – Develoger Commented Feb 8, 2013 at 15:22
3 Answers
Reset to default 4Works fine, you'll just have to prevent the default link action, so the browser won't try to follow it.
$('#link').click(function (evt){
$('input#geo_title').removeAttr('value');
$("input#geo_title").focus();
evt.preventDefault();
});
try to remove the default focus from the link by adding href=#!
<a href="#!" id="link">Clickable Link</a>
You haven't wrapped your code in
$( function() { });
or
$(document).ready( function() { });
本文标签: javascriptSet focus on input element after a link is clickedStack Overflow
版权声明:本文标题:javascript - Set focus on input element after a link is clicked - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741315089a2371867.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论