将 HTMLElement 的 focus
函数存储在变量中的正确上下文是什么?
我试过了,
var elem = document.getElementById('elem');
var focus = elem.focus.bind(document); // focus() Illegal Invocation
var focus2 = elem.focus.bind(elem); // focus2() Illegal Invocation
最佳答案
将其包装到您自己的函数中:
var elem = document.getElementById('elem');
var focusElem = function(){ elem.focus(); };
focusElem();
关于javascript - 如何在变量中缓存 HTMLElement.focus?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41762576/