2010-05-09 38 views

回答

3

在對象上使用focus()方法。

例如:

document.getElementById("something").focus(); 
... 
<input type='text' id='something' /> 
+0

謝謝。我實際上是在發佈之前嘗試過的,但它似乎沒有正確的工作。我一定沒有把頁面刷新得足夠好。 :P – Rayne 2010-05-09 21:36:20

1

你嘗試使用Google呢?

document.getElementById("textboxId").focus();

+2

我檢查過以確保這個問題不是重複的。我相當肯定,這是提出問題的唯一先決條件。我覺得任何以前沒有問過的問題都是對這個網站的一個體面的貢獻,只要它不是愚蠢的。 – Rayne 2010-05-09 21:34:55

+0

@Rayne:你說得對。不要注意那些說不然的話。 – 2010-05-09 21:39:19

2

,你必須先選擇元素,然後使用對焦()重點是:P

function hokusfocus(e) 
{ 
    var fokus = document.getElementById(e); 
    fokus.focus(); 
} 

onload = hokusfocus("yourId"); /* makes sure your document is loaded before the focus */ 
+0

哈哈。我非常喜歡這個真棒名字! – 2010-05-09 21:32:25

+1

有趣的功能名稱;) – BradBrening 2010-05-09 21:33:41

+1

我不是這麼快的typer。所以我必須用我的想象力來獲得積分:P – meo 2010-05-09 21:37:22

0

使用自動對焦功能屬性是這樣的:

<html> 
<head> 

</head> 
<body> 
<dl> 
<dt><label>username:</label><dt> 
<dd><input type="text" autofocus></dd> 

<dt><label>password:</label><dt> 
<dd><input type="password"></dd> 

</dl> 
</body> 

相關問題