jquery焦点,但具有更准确的位置
-
06-07-2019 - |
题
你可以很容易地从网站或任何网站找到焦点()答案..但我想知道的是,我如何在输入框中插入的内容后使用焦点。
$("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中它从开始启动光标。任何解决方案?
解决方案
看看这个问题: jQuery在文本区域设置光标位置
其他提示
您可以通过在更改事件上触发来聚焦输入区域:
$("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();
}
});
希望它有所帮助,思南。
不隶属于 StackOverflow