jQuery点击input使光标移动到最后或指定位置
你要知道面对一个 处女座的 需求者, focus()是远远不够的。 比如说“我点进去的时候光标要在最后,这样我就不用再把光标移动到最后去添加东西了。” oh,让我先撞下墙。 我们需要扩展jQuery: //光标放在最后 $("#文本框ID").textFocus();光标放在第二个字符
你要知道面对一个 处女座的 需求者, focus()是远远不够的。
比如说“我点进去的时候光标要在最后,这样我就不用再把光标移动到最后去添加东西了。”
oh,让我先撞下墙。
我们需要扩展jQuery:
//光标放在最后 $("#文本框ID").textFocus();光标放在第二个字符后面 $("#文本框ID").textFocus(2); (function($){ $.fn.textFocus=function(v){ var range,len,v=v===undefined?0:parseInt(v); this.each(function(){ if($.browser.msie){ range=this.createTextRange(); v===0?range.collapse(false):range.move("character",v); range.select(); }else{ len=this.value.length; v===0?this.setSelectionRange(len,len):this.setSelectionRange(v,v); } this.focus(); }); return this; } })(jQuery);
另一种简单的方法:
var t=$(“#”+id).val();
$(“#”+id).val(“”).focus().val(t);
建议采用第一种方法。
原文地址:jQuery点击input使光标移动到最后或指定位置, 感谢原作者分享。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

Dreamweaver CS6
Visual web development tools

Dreamweaver Mac version
Visual web development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
