//當失去交點以后 讓文本框內的文字獲得焦點 並且光標移到最后一個字后面 function myfocus(myid) { if(isNav){ document.getElementById(myid).focus();// 獲取焦點 }else{ setFocus.call(document.getElementById(myid)); } } var isNav = (window.navigator.appName.toLowerCase().indexOf("netscape")>=0); var isIE = (window.navigator.appName.toLowerCase().indexOf("microsoft")>=0); function setFocus() { var range = this.createTextRange(); //建立文本選區 range.moveStart('character', this.value.length); //選區的起點移到最后去 range.collapse(true); range.select(); }
jquery中focus()函數實現當對象獲得焦點后自動把光標移到內容最后
jquery獲取焦點后光標在字符串后,當input獲得焦點后,自動把光標移到文本內容的最后,jQuery用focus()使文本輸入框獲得焦點且焦點在文字的最右的方法
//獲取焦點后光標在字符串后 //其原理就是獲得焦點后重新把自己復制粘帖一下 var t=$("#"+id).val(); $("#"+id).val("").focus().val(t);