I have this code to detect the keypress and direct input towards my searchbar with id="search".
我有这个代码来检测按键和直接输入到我的搜索栏id =“search”。
$( document ).keypress(function() {
$("#search").focus();
I also have a bootstrap modal dialog with input fields. Is there a way to detect if the modal is open or not--if it is open, direct the input to the first field of the modal?
我还有一个带输入字段的bootstrap模态对话框。有没有办法检测模态是否打开 - 如果它是打开的,将输入指向模态的第一个字段?
<div class="modal fade" id="signup" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
</div>
<div class="modal-body">
<input id="input_modal" placeholder="" size="14" autofocus="autofocus"><br>
<input type="submit" value="Submit" class="hide"/>
</div>
</div>
</div>
</div>
2 个解决方案
#1
1
For Bootstrap 3:
对于Bootstrap 3:
if ($("element").data('modal') && $("element").data('modal').isShown) {
//do something
}
#2
0
$('#myModal').on('shown.bs.modal', function () {
$("#search").focus();
})
#1
1
For Bootstrap 3:
对于Bootstrap 3:
if ($("element").data('modal') && $("element").data('modal').isShown) {
//do something
}
#2
0
$('#myModal').on('shown.bs.modal', function () {
$("#search").focus();
})