Find first empty input field

前端 未结 4 2055
温柔的废话
温柔的废话 2021-01-05 08:33

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

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


        
4条回答
  •  甜味超标
    2021-01-05 09:21

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

    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.

提交回复
热议问题