input
按下按钮后无法自动转移焦点。
onclick
在html
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.4/css/bootstrap.min.css" integrity="2hfp1SzUoho7/TsGGGDaFdsuuDL0LX2hnUp6VkX3CUQ2K4K+xjboZdsXyp4oUHZj" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.4/js/bootstrap.min.js" integrity="VjEeINv9OSwtWFLAtmc4JCtEJXXBub00gtSnszmspDLCtC0I4z4nqz7rEFbIZLLU" crossorigin="anonymous"></script>
<div class="btn-group w-100">
<button type="button" class="btn border" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" onclick="$('#inputAutocompleteAccesses').focus();">Выбрать право</button>
<div class="dropdown-menu col-12 shadow text-center">
<div class="container-fluid p-0">
<div class="row m-0 p-0">
<input class="form-control mx-2" oninput="sendRequestAccessJson($(this).val());" id="inputAutocompleteAccesses" placeholder="Введите право" />
</div>
<div id="autocompleteAccesses">
</div>
<div class="row mx-1 justify-content-center">
<p>1</p>
</div>
<div class="row mx-1 justify-content-center">
<p>2</p>
</div>
<div class="row mx-1 justify-content-center">
<p>3</p>
</div>
</div>
</div>
</div>
现在我决定了:
function f(){
$('#inputAutocompleteAccesses').focus();
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.4/css/bootstrap.min.css" integrity="2hfp1SzUoho7/TsGGGDaFdsuuDL0LX2hnUp6VkX3CUQ2K4K+xjboZdsXyp4oUHZj" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.4/js/bootstrap.min.js" integrity="VjEeINv9OSwtWFLAtmc4JCtEJXXBub00gtSnszmspDLCtC0I4z4nqz7rEFbIZLLU" crossorigin="anonymous"></script>
<div class="btn-group w-100">
<button type="button" class="btn border" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" onclick="setTimeout(f, 10);">Выбрать право</button>
<div class="dropdown-menu col-12 shadow text-center">
<div class="container-fluid p-0">
<div class="row m-0 p-0">
<input class="form-control mx-2" oninput="sendRequestAccessJson($(this).val());" id="inputAutocompleteAccesses" placeholder="Введите право" />
</div>
<div id="autocompleteAccesses">
</div>
<div class="row mx-1 justify-content-center">
<p>1</p>
</div>
<div class="row mx-1 justify-content-center">
<p>2</p>
</div>
<div class="row mx-1 justify-content-center">
<p>3</p>
</div>
</div>
</div>
</div>
但它是怎么回事?
使用引导事件。