1

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

我希望在加载页面时无需用户点击。

<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>
4

2 回答 2

4
 $(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
 });
于 2012-05-11T15:19:58.057 回答
2

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

$('.btn-modal:first').click();
于 2012-05-11T15:17:06.053 回答