2010-05-09 40 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> 

相关问题