$( document ).ready(function(){}); 永远不会在模态中到达,因为加载页面时已经触发了此事件(模态在之后加载...)
尝试直接插入脚本,如下所示:
<script type="text/javascript">
$( "#first" ).focus(function() {
alert( "Handler for .focus() called." );
});
</script>
shown.bs.modal
事件将被触发。这是例子。
$('#myModal').on('shown.bs.modal', function () {
$('#myInput').trigger('focus')
})
Full documentation.
https://getbootstrap.com/docs/4.0/components/modal/
试试这个我已经准备好这个功能了
$('#myModal').on('shown.bs.modal', function () {
// Your script here
});
$(document).on('shown.bs.modal', '#myModal', function () {
// Your script here
});