你可以从网站或任何网站上轻松找到焦点()答案..但我想知道的是,我如何在输入框内插入的内容后使用焦点。
$("input").val('@user').focus(); // this goes to start of the input box and foucs from start, but i want it to focus after the @user
$("input").val('@user today i did new things').focus(5); // i added 5 in focus method, obviously its not supported yet!, but the idea behind is, to focus it after @user from complete word.
编辑:
我刚看到它在firefox上工作正常,但在chrome中它从开始启动光标。任何解决方案?
答案 0 :(得分:0)
答案 1 :(得分:0)
您可以通过在更改事件上触发来聚焦输入区域:
$("input").change(function(){
$(this).focus();
});
如果你想检查输入的字符数,可以对其回调进行控制:
//will focus if typed text's length is greater than 5
$("input").change(function(){
if($(this).val().length > 5){
$(this).focus();
}
});
希望它有所帮助,思南。