javascript - 选择第一个输入,但不要选择 type=hidden

标签 javascript jquery jquery-selectors hidden

我想关注第一个不是 type=hidden 的输入元素。我已经做到了这一点,但它仍会尝试聚焦隐藏的元素。

$('#content input:first').focus();

最佳答案

使用 :visible 选择器:

$('#content input:visible:first').focus();

:可见 docs :

Description: Selects all elements that are visible. Elements can be considered hidden for several reasons:

  • They have a CSS display value of none.
  • They are form elements with type="hidden".
  • Their width and height are explicitly set to 0.
  • An ancestor element is hidden, so the element is not shown on the page.

如果这对你来说太多了,使用Attribute Not Equal Selector:

$('#content input[type!="hidden"]:first').focus();

属性不等于选择器 docs :

Description: Select elements that either don't have the specified attribute, or do have the specified attribute but not with a certain value.

关于javascript - 选择第一个输入,但不要选择 type=hidden,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9699234/

相关文章:

javascript - 我应该将服务器端监听器放在 io 或 socket.io 的套接字上吗?

javascript - 我怎样才能改变我的 meteor 应用程序中的盒子高度

javascript - 如何使用 jQuery 替换文本区域中的特定元素?

jquery - 什么 JQuery 选择器会排除父项与给定选择器匹配的项?

javascript - Angular Directive(指令)表行问题

javascript - 如何从 json 中删除\r?

jquery - 非法调用 (jQuery)

php - 如何在 MySql 查询方法中写入开始日期和开始日期?

jQuery:按数据属性选择某些元素失败 - 为什么?

javascript - 如何使用 $(this) 构建选择器