2017-08-04 51 views
0

当用户从列表框中选择一个项目时,焦点仍然存在,所以如果他按下“输入”,它仍然存在。我想在选中后自动改变焦点。如何在选择选择器后选择一个项目后自动对焦按钮?

我使用这个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> 

这是NeXTSTEP的按钮:

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

如果'nextStep'是一个类,岂不是' $(“。nextStep”)。focus()'然后 –

回答

0

$(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>

相关问题