2017-08-04 77 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>

相關問題