10 examples of 'js set focus' in JavaScript

Every line of 'js set focus' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
115setFocus(){//获取焦点
116 if(JMain.JFocusControl)JMain.JFocusControl.lostFocus();
117 this.focus=true;
118 JMain.JFocusControl=this;
119 if(this.onFocus)this.onFocus();
120}
23export function focusInput(element) {
24 if (!element) return;
25
26 const textNode = findLastTextNode(element);
27 if (textNode) {
28 const range = document.createRange();
29 range.setStart(textNode, textNode.length);
30 range.collapse(true);
31
32 const selection = window.getSelection();
33 selection.removeAllRanges();
34 selection.addRange(range);
35 }
36
37 element.focus();
38}
113function inputFocus(obj) {
114 $(obj).click();
115}
113focus() {
114 if (this.lastSelection) this.editor.setSelection(this.lastSelection);
115 else this.root.focus();
116}
62public focus() {
63 const textarea = this.textarea.current
64
65 if (textarea) {
66 setTimeout(() => {
67 textarea.blur()
68 textarea.focus()
69 })
70 }
71}
500focus() {
501 const el = this._getContainer();
502 if (el) {
503 el.focus();
504 }
505}
126function focus(id) {
127 var inputField = document.getElementById(id);
128 if (inputField != null && jQuery(inputField).is(":text,textarea,:password") &&
129 inputField.value && inputField.value.length != 0) {
130 if (inputField.createTextRange) {
131 var FieldRange = inputField.createTextRange();
132 FieldRange.moveStart('character', inputField.value.length);
133 FieldRange.collapse();
134 FieldRange.select();
135 } else if (inputField.selectionStart ||
136 (inputField.selectionStart != undefined && inputField.selectionStart == '0')) {
137 var elemLen = inputField.value.length;
138 inputField.selectionStart = elemLen;
139 inputField.selectionEnd = elemLen;
140 inputField.focus();
141 }
142 } else if (inputField != null) {
143 inputField.focus();
144 }
145}
152async focus() {
153 await this._frame.focus(this._selector)
154}
235focus () {
236 this._input && this._input.focus()
237}
21focus() {
22 const self = ReactDOM.findDOMNode(this) as HTMLElement;
23 const input = self.tagName === "INPUT" ? self as HTMLInputElement : self.querySelector("input");
24 console.log(self, input);
25 input.select();
26}

Related snippets