如何将焦点设置为独立于id的HTML表单中的第一个输入元素? [英] How to set the focus to the first input element in an HTML form independent from the id?

查看:145
本文介绍了如何将焦点设置为独立于id的HTML表单中的第一个输入元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种简单的方法可以在加载第一个输入元素(textbox,dropdownlist,...)时在设置焦点(输入光标)而不必知道元素的ID?

我想实现它作为我的web应用程序的所有我的页面/形式的通用脚本。

您也可以尝试使用基于jQuery的方法:

  

解决方案

$ c $> $(document).ready(function(){
$('form:first *:input [type!= hidden]:first')。 ;


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?

I would like to implement it as a common script for all my pages/forms of my web application.

解决方案

You can also try jQuery based method:

$(document).ready(function() {
    $('form:first *:input[type!=hidden]:first').focus();
});

这篇关于如何将焦点设置为独立于id的HTML表单中的第一个输入元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆