加载单击链接

Onload click the link

本文关键字:链接 单击 加载      更新时间:2023-09-26

目前,以下代码仅在用户单击链接时加载。

我希望在加载页面时发生这种情况,而无需用户单击。

<script>
$(document).ready(function() {
    // Support for AJAX loaded modal window
    $(document).on('click', '.btn-modal', function() {
        $.get($(this).attr('data-target'), function(data) {
            $('#modal').html(data);
            $('#modal').modal('show');
        }, 'html');
    });
});​
</script>
<!-- Modal window to load dynamic content -->
<div class="modal hide fade customDialog" id="modal"></div>
<a class="btn btn-modal" data-target="page.html" >Launch Modal</a>
 $(document).ready(function() {
        // Support for AJAX loaded modal window
        $(document).on('click','.btn-modal',function() {
            $.get($(this).attr('data-target'), function(data) {
             $('#modal').html(data);
             $('#modal').modal('show');
           }, 'html');
       });
      // here write
      $('.btn-modal').click();
     // if you have multiple button then keep filter
     // eg.
     // $('.btn-modal:eq(0)').click(); // for first button
     // $('.btn-modal:eq(1)').click(); // for second button and so more
 });

只需将其添加到$(document).ready()处理程序的末尾:

$('.btn-modal:first').click();