我想关注第一个不是 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/