将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
答案 0 :(得分:-1)
将其包装到您自己的功能中:
var elem = document.getElementById('elem');
var focusElem = function(){ elem.focus(); };
focusElem();