使用选择选取器选择项目后,如何自动聚焦按钮?



当用户从列表框中选择一个项目时,焦点将保留在那里,因此如果他按"Enter",它就会保留在那里。我想在选择后自动更改焦点。

我正在使用这个jquery函数:

$(function() {
$("nextStep").focus();
});

"nextStep"是按钮的类,它可以工作,但我想在组合框咏叹调扩展的属性为假时实现它。你能解释一下我该怎么做吗?

这是列表框:

<button type="button" class="btn dropdown-toggle btn-default" 
data-toggle="dropdown" role="button" data-id="tn_workType" 
title="Disoccupato" aria-expanded="false">
<span class="filter-option pull-left">Disoccupato</span>&nbsp;
<span class="bs-caret">
<span class="caret"></span>
</span>
</button>

这是下一步按钮:

<a href="javascript:void(0)" class="btn btn-white btn-rounded nextStep" 
tabindex="0">Avanti →</a>

$(function() {
$('select').change(function (e) {
$('.nextStep').focus();
});   
$('.nextStep').click(function(){
alert("Avanti buttonn clicked")
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<select class="btn btn-toogle btn-default">
<option>Option1</option>
<option>Option2</option>
</select>
When the user choose an item from the list box, the focus remain there, so if he press "enter" it remains there. I'd like to automatically change the focus after the pick.
I'm using this jquery function:
$(function() {
$("nextStep").focus();
});
"nextStep" is the class of the button and it works, but I'd like to make it happen when the attribute of the combobox aria-expanded is false. Can you explain me how can I do this please?
This is the listbox:
This is the nextStep button:
<a href="javascript:void(0)" class="btn btn-white btn-rounded nextStep" 
tabindex="0">Avanti →</a>

最新更新