|
阅读:4874回复:4
【GreaseMonkey脚本】让网页中的第一个文本框自动获得焦点
很多网页往往没有专门把焦点设置在第一个文本框中,甚至我在FF中打开Baidu也有这样的问题,焦点竟然也不在文本框中(事实上我看了baidu的代码,onload事件是把焦点置到文本框中了,不过在FF中无效,可能是同我的其他GreaseMonkey脚本冲突了),因此写了这个脚本方便输入。
// ==UserScript==
// @namespace http://www.firefox.net.cn
// @name Focus to First InputBox
// @description Set focus to the first inputBox in the webpage
// @include http://*
// ==/UserScript==
(function() {
window.addEventListener('DOMContentLoaded', setFocus(), false);
function setFocus()
{
var inputFields = document.getElementsByTagName('input');
if(inputFields)
{
var type = '';
var len = inputFields.length;
for (i = 0; i < len; i++)
{
type = inputFields[i].type ? inputFields[i].type.toLowerCase() : '';
if ('text' == type && !inputFields[i].hasFocus)
{
inputFields[i].focus();
return;
}
}
}
}
})();
使用方法是把这段代码复制到一文本文件中,并保存为setfocus.user.js,然后用FF打开这个文件,安装GreaseMoneky的话,会提示你安装。 |
|
|
1楼#
发布于:2006-05-21 13:44
<!-- w --><a class="postlink" href="http://www.baidu.com">www.baidu.com</a><!-- w --> 有效果
|
|
|
2楼#
发布于:2006-05-21 13:44
在baidu里怎么没效果
|
|
|
3楼#
发布于:2006-05-21 13:44
顶!!!
|
|
|
|
4楼#
发布于:2006-05-21 13:44
好用呀 顶你
|
|
|