$('#login').click(function(){ $('#username').focus(); if ($(":test").val().length == 0){ $('#username') }else if ($(':password').val().length == 0){ } });
<p id="errormessage"></p> <input id="username" type="test" name="username"><br> <input type="password" name="password"><br> <button id="login">登陆</button>