Javascript 为什么focus()不适用于div元素?
为什么focus元素没有改变?我不得不在“hello world div”元素中添加tabIndex属性,这样focus()和blur()就可以工作了 如果这个问题与React无关,请考虑删除Javascript 为什么focus()不适用于div元素?,javascript,Javascript,为什么focus元素没有改变?我不得不在“hello world div”元素中添加tabIndex属性,这样focus()和blur()就可以工作了 如果这个问题与React无关,请考虑删除reactjs标记并修改标题。 var targetElement = document.getElementsByClassName('hello-world-div')[0]; var focusElement = document.activeElement; console.log("c
reactjs
标记并修改标题。
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