// jQuery 获取光标位置函数调用示例 $("input[name='username']").getCursorPosition();
jQuery.fn.getCursorPosition = function(){ if(this.length == 0) return -1; return $(this).getSelectionStart(); };
// jQuery 设置光标位置函数调用示例 $("input[name='username']").setCursorPosition(5);
jQuery.fn.setCursorPosition = function(position){ if(this.length == 0) return this; return $(this).setSelection(position, position); };
// jQuery 获取文本选择函数调用示例 $("input[name='username']").getSelection();
jQuery.fn.getSelection = function(){ if(this.length == 0) return -1; var s = $(this).getSelectionStart(); var e = $(this).getSelectionEnd(); return this[0].value.substring(s,e); };
// jQuery 获取文本选择起始位置函数调用示例 $("input[name='username']").getSelectionStart();
jQuery.fn.getSelectionStart = function(){ if(this.length == 0) return -1; var input = this[0]; var pos = input.value.length; if (input.createTextRange) { var r = document.selection.createRange().duplicate(); r.moveEnd('character', input.value.length); if (r.text == '') pos = input.value.length; pos = input.value.lastIndexOf(r.text); } else if(typeof(input.selectionStart)!="undefined") pos = input.selectionStart; return pos; };
// jQuery 获取文本选择结束位置函数调用示例 $("input[name='username']").getSelectionEnd();
jQuery.fn.getSelectionEnd = function(){ if(this.length == 0) return -1; var input = this[0]; var pos = input.value.length; if (input.createTextRange) { var r = document.selection.createRange().duplicate(); r.moveStart('character', -input.value.length); if (r.text == '') pos = input.value.length; pos = input.value.lastIndexOf(r.text); } else if(typeof(input.selectionEnd)!="undefined") pos = input.selectionEnd; return pos; };
// jQuery 设置文本选择函数调用示例 $("input[name='username']").setSelection(4, 20);
jQuery.fn.setSelection = function(selectionStart, selectionEnd) { if(this.length == 0) return this; var input = this[0]; if (input.createTextRange) { var range = input.createTextRange(); range.collapse(true); range.moveEnd('character', selectionEnd); range.moveStart('character', selectionStart); range.select(); } else if (input.setSelectionRange) { input.focus(); input.setSelectionRange(selectionStart, selectionEnd); } return this; };
jQuery 커서 함수의 목적은 무엇입니까?
selectionStart 및 선택 속성은 HTML DOM의 일부이며 jQuery와 함께 사용하여 입력 필드 또는 텍스트 영역에서 선택된 텍스트의 시작 및 종료 위치를 설정하거나 설정할 수 있습니다.
setSelectionRange 메소드는 무엇이며 jQuery에서 사용하는 방법은 무엇입니까?setSelectionRange 메소드는 입력 필드 또는 텍스트 영역에서 현재 텍스트 선택의 시작 및 끝 위치를 설정하는 DOM 메소드입니다.
jQuery의 입력 필드 끝으로 커서를 이동하는 방법은 무엇입니까?
입력 필드에서 특정 텍스트 범위를 선택하기 위해 jQuery를 사용하는 방법은 무엇입니까?
jQuery 커서 함수를 모든 유형의 입력 필드와 함께 사용할 수 있습니까?
입력 필드에서 현재 커서 위치를 얻기 위해 jQuery를 사용하는 방법은 무엇입니까?
모든 브라우저에서 jQuery 커서 함수를 사용할 수 있습니까?
위 내용은 6 jQuery 커서 함수의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!