之前在iphone上做開發時遇到一個問題,在一般的正常瀏覽器上輸入以下代碼:
1
2
|
var
apple = document.getElementById(
'abc'
);
apple.focus();
|
就能將焦點聚集在輸入框上;但是在ios上不行
解決方案:
只有通過綁定在事件上的函數觸發,才能聚焦,例如:
1
2
3
4
|
var
apple = document.getElementById(
'abc'
);
button.addEventListener(
'click'
,
function
(){
apple.focus();
});
|
但是不能將apple.focus()
封裝在函數中再由事件觸發,這樣也會失效