Html 指向输入字段
我不知道有些网站是怎么做到的,但有时当我进入一些网站时,它会自动点击我的输入栏。例如,我单击搜索,然后在搜索页面上它为我“单击”了字段,所以我只需在其中键入而不单击我自己。我怎样才能做到这一点?您可以通过在所需的输入字段上设置所谓的“焦点”来做到这一点。这可以通过使用javascript实现。这里有一个例子,我希望它能帮助你Html 指向输入字段,html,Html,我不知道有些网站是怎么做到的,但有时当我进入一些网站时,它会自动点击我的输入栏。例如,我单击搜索,然后在搜索页面上它为我“单击”了字段,所以我只需在其中键入而不单击我自己。我怎样才能做到这一点?您可以通过在所需的输入字段上设置所谓的“焦点”来做到这一点。这可以通过使用javascript实现。这里有一个例子,我希望它能帮助你 <html> <head> <title>Focus Example</title> <script>
<html>
<head>
<title>Focus Example</title>
<script>
function setFocus() {
var loginForm = document.getElementById("login");
if (loginForm) {
loginForm["user"].focus();
}
}
</script>
</head>
<body onload="setFocus();">
<form id="login" method="post" action="">
<table>
<tr>
<td><div align="left">User Name:</div></td>
<td><div align="left"><input name="user" type="text"
size="30" maxlength="30" tabindex="1" /></div></td>
</tr>
<tr>
<td><div align="left">Password:</div></td>
<td><div align="left"><input name="password" type="password"
size="30" maxlength="50" tabindex="2" /></div></td>
</tr>
</form>
</body>
</html>
焦点示例
函数setFocus(){
var loginForm=document.getElementById(“登录”);
if(loginForm){
loginForm[“用户”].focus();
}
}
用户名:
密码:
您可以通过在所需的输入字段上设置所谓的“焦点”来实现这一点。这可以通过使用javascript实现。这里有一个例子,我希望它能帮助你
<html>
<head>
<title>Focus Example</title>
<script>
function setFocus() {
var loginForm = document.getElementById("login");
if (loginForm) {
loginForm["user"].focus();
}
}
</script>
</head>
<body onload="setFocus();">
<form id="login" method="post" action="">
<table>
<tr>
<td><div align="left">User Name:</div></td>
<td><div align="left"><input name="user" type="text"
size="30" maxlength="30" tabindex="1" /></div></td>
</tr>
<tr>
<td><div align="left">Password:</div></td>
<td><div align="left"><input name="password" type="password"
size="30" maxlength="50" tabindex="2" /></div></td>
</tr>
</form>
</body>
</html>
焦点示例
函数setFocus(){
var loginForm=document.getElementById(“登录”);
if(loginForm){
loginForm[“用户”].focus();
}
}
用户名:
密码:
加载页面时使用
这样的话:
<script type="text/javascript">
window.onload = function () {
document.getElementById("id-of-some-input-field").focus();
}
</script>
window.onload=函数(){
document.getElementById(“某个输入字段的id”).focus();
}
加载页面时使用
这样的话:
<script type="text/javascript">
window.onload = function () {
document.getElementById("id-of-some-input-field").focus();
}
</script>
window.onload=函数(){
document.getElementById(“某个输入字段的id”).focus();
}