-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DOM那些事儿 #78
Comments
如何用js生成标签
<audio></audio>
<p></p> 如果实在不放心,打印出标签可以看到: console.dir(document.createElement('p')) // console.dir(document.createElement('p'))打印出相同的结果
// localName: 'p', nodeName: 'P'
|
如何模拟focus一个DOMelement.focus(options); // Object parameter
https://developer.mozilla.org/en-US/docs/Web/API/HTMLOrForeignElement/focus 聚焦后光标如何定位到尾部this.$refs.richTextEditor.focus();
const el = this.$refs.richTextEditor;
const range = document.createRange();
const sel = window.getSelection();
console.log(document.activeElement);
const tailIndex = el.childNodes.length;
const tailNode = el.childNodes[tailIndex - 1];
range.setStart(tailNode, tailNode.length);
range.collapse(true);
sel.removeAllRanges();
sel.addRange(range); 如何获取元素的focus状态// target element
const targetElement = document.getElementById('targetElement');
// check for focus
const isFocused = (document.activeElement === targetElement); // vue
computed: {
isEditorFocused() {
const targetElement = this.$refs.richTextEditor;
return targetElement === document.activeElement;
},
} https://stackoverflow.com/questions/36430561/how-can-i-check-if-my-element-id-has-focus |
如何检测一个event listener在一个DOM上是否已经注册?
Note, however that when using an anonymous function as the handler, such listeners will NOT be identical, because anonymous functions are not identical even if defined using the SAME unchanging source-code simply called repeatedly, even if in a loop. 即使重复注册事件监听器,也不会重复触发两次,重复的实例会被移除。 |
DOM进阶之Node Interface |
The text was updated successfully, but these errors were encountered: