2

focus将 HTMLElement的函数存储在变量中的正确上下文是什么?

我试过了,

var elem = document.getElementById('elem');
var focus = elem.focus.bind(document); // focus() Illegal Invocation
var focus2 = elem.focus.bind(elem); // focus2() Illegal Invocation
4

1 回答 1

-1

将其包装到您自己的函数中:

var elem = document.getElementById('elem');
var focusElem = function(){ elem.focus(); };
focusElem();
于 2017-01-20T11:40:52.517 回答