var targetElement = document.getElementsByClassName('hello-world-div')[0];
var focusElement = document.activeElement;
console.log("currently focused on: ");
console.log(focusElement); //this shows the body element
targetElement.focus();
focusElement = document.activeElement;
console.log("forced focus on: ");
console.log(focusElement); // this still shows the body element
为什么焦点元素不会改变?
答案 0 :(得分:0)
我必须将tabIndex属性添加到" hello-world-div"元素,以便focus()和blur()可以工作!