如何将焦点设置为独立于ID的HTML格式的第一个输入元素? [英] How do I set the focus to the first input element in an HTML form independent from the id?
本文介绍了如何将焦点设置为独立于ID的HTML格式的第一个输入元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有一种简单的方法,可以在加载时在第一个输入元素上设置网页的焦点(输入光标)(文本框,下拉列表等)页面而不必知道元素的ID?
Is there a simple way to set the focus (input cursor) of a web page on the first input element (textbox, dropdownlist, ...) on loading the page without having to know the id of the element?
我想将其作为Web应用程序所有页面/表单的通用脚本来实现.
I would like to implement it as a common script for all my pages/forms of my web application.
推荐答案
您还可以尝试基于jQuery的方法:
You can also try jQuery based method:
$(document).ready(function() {
$('form:first *:input[type!=hidden]:first').focus();
});
这篇关于如何将焦点设置为独立于ID的HTML格式的第一个输入元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文