2010-01-19 199 views

回答

8
<input name="input1" id="input1" value="" /> 

window.onload = init; 

function init(){ 
document.getElementById("input1").focus(); 
} 

這應該做

+0

你應該保持你的大括號在函數init() – Matt 2010-01-19 09:37:29

+0

的同一行上,我確實應該這樣做,但這種方式在處理大塊代碼時看起來更容易處理,無論如何我都修復了它:) – ant 2010-01-19 09:41:46

+0

c0mrade:什麼是您的其他答案?爲什麼被刪除? – 2010-01-23 19:21:36

1

使用focus()方法輸入body.onLoad

3
window.onload = function(){ 
    document.getElementById("InputBoxID").focus(); 
}; 
0
<input type="text" autofocus="autofocus" name="FirstName"/> 

文本字段獲取聚焦時,頁面被載入..

有關更多信息,請檢查該Autofocus-Attribute鏈接