2017-01-20 6 views
2

HTMLElementの関数focusを変数に格納する正しいコンテキストは何ですか?私が試した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 

答えて

-1

独自の関数にそれをラップ:

var elem = document.getElementById('elem'); 
var focusElem = function(){ elem.focus(); }; 
focusElem(); 
関連する問題