查找第一个空的输入字段 [英] Find first empty input field

查看:159
本文介绍了查找第一个空的输入字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个简单的选择器在我的表单中找到第一个空文本输入字段,但跳过了密码类型输入:

This simple selector finds the first empty text input field in my form but skips over password type inputs:

$('input:text[value=""]:first').focus();

在上面的语句中,有没有一种巧妙的方式来表达:text或:password?

Is there a neat way to say :text or :password in the above statement?

推荐答案

$('input:text[value=""]').add('input:password[value=""]').first().focus();

我认为没有更好的方法.这就是我在查看 @Hari Das 答案之前的想法,该问题虽然有问题,但给我带来了替代解决方案:

I don't think there is a better way. That's what I thought before taking a look at @Hari Das answer which has an issue but brings alternative solution to my mind:

$('input:text[value=""],input:password[value=""]').first().focus()

选择一个更容易理解的内容.

Choose the one which is more readable to you.

这篇关于查找第一个空的输入字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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