我有一个注册表单,第一个element
是textbox
,第二个element
是select
。
当我按下回车键时,我想将焦点设置在select
元素。
$('#newUserId').keypress(function(event){
if (event.which == 13)
$('#newUserId:first').focus();
});
我也环顾四周,甚至this link和this link也无济于事,当我按下回车键时,它什么也没做。但是当我检查将焦点设置在其他textbox
元素上时,它确实改变了焦点。
我的HTML表单:
<form name='formCreateNewUser' id='formCreateNewUser' method='post' action=''>
<label> Create New User </label> <br />
<input autocomplete='off' name='newUserId' id='newUserId' class='newUser'
type='text' size='17' maxlength='17' placeholder='ID No.'
/> <span id='newUserIdResult'> </span><br /><br />
<select name='newUserType' id='newUserType' class='newUser'>
<option class='newUser' value=0>User Type</option>
<option class='newUser' value=1>Student</option>
<option class='newUser' value=2>Teacher</option>
<option class='newUser' value=5>Admin</option>
</select> <br /><br />
<input autocomplete='off' name='newUserPass' id='newUserPass' class='newUser'
size='17' maxlength='17' placeholder='Password' type='password'
/> <br /><br />
<input autocomplete='off' name='newUserConfPass' id='newUserConfPass' class='newUser'
size='17' maxlength='17' placeholder='Confirm Password' type='password'
/> <br /><br />
<input autocomplete='off' name='newUserFirstName' id='newUserFirstName' class='newUser'
size='17' maxlength='17' placeholder='First Name' type='text'
/> <br /><br />
<input autocomplete='off' name='newUserMiddleName' id='newUserMiddleName' class='newUser'
size='17' maxlength='17' placeholder='Middle Name' type='text'
/> <br /><br />
<input autocomplete='off' name='newUserLastName' id='newUserLastName' class='newUser'
size='17' maxlength='17' placeholder='Last Name' type='text'
/> <br /><br />
<button name='newUserSubmit' id='newUserSubmit' class='operationstylebutton' type='button' >Create User</button>
</form>
答案 0 :(得分:2)
$('#newUserId').on('keyup', function(e) {
if ( e.keyCode == 13 )
$('#newUserType').focus();
});
答案 1 :(得分:2)
Demo添加了一个用于突出显示效果的类
$('#newUserId').keypress(function (event) {
if (event.which == 13)
{$('#newUserType').addClass("highlght").focus();}
});