Open FrankKai opened 6 years ago
var element = document.createElement(tagName[, options]);
<audio></audio>
<p></p>
如果实在不放心,打印出标签可以看到:
console.dir(document.createElement('p')) // console.dir(document.createElement('p'))打印出相同的结果
// localName: 'p', nodeName: 'P'
element.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);
// 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 cv前端开发。
Multiple identical event listeners If multiple identical EventListeners are registered on the same EventTarget with the same parameters, the duplicate instances are discarded. They do not cause the EventListener to be called twice, and they do not need to be removed manually with the removeEventListener() method.
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.
即使重复注册事件监听器,也不会重复触发两次,重复的实例会被移除。 无法检测listener是否存在。