javascript - 在其他页面打开 jQuery Fancybox

标签 javascript jquery html css

我在页面 index.html 中有一个链接,我需要打开一个位于另一页面中名为 index2.html 的 div,但我做不到。

我的代码是这样的:

index.html 中的链接

<a href="#modal" id="open-modal">Open Modal</a> 

index2.html页面内容:

    <div id="modal" class="style-modal">                  
        <a id="close_modal" href="#" title="close modal"></a>
        <div id="content-modal">
          <p>Content here</p>
        </div>                  
    </div>

这是我在 efect.js 中的代码:

   $(document).ready(function(){
        $("#open_modal").click(function(){

            $( '#modal' ).fadeIn();
            $( '#bg-modal' ).fadeTo( 500, .5 );
         });

        $("#close_modal").click(function(){

            $( '#modal, #bg-modal' ).fadeOut();
        });
    });

请帮帮我。

最佳答案

尝试使用window.location.hash:

index.html 中的链接:

<a href="http://example.com/index2.html#show-modal" id="open-modal">Open Modal</a>

index2.html页面内容:

<div id="modal" class="style-modal">                  
    <a id="close_modal" href="#" title="close modal"></a>
    <div id="content-modal">
      <p>Content here</p>
    </div>                  
</div>

这是我在 efect.js 中的代码:

function showModal() {
    $( '#modal' ).fadeIn();
    $( '#bg-modal' ).fadeTo( 500, .5 );
}

$(document).ready(function(){
        $("#open_modal").on('click', showModal);

        $("#close_modal").click(function(){
            $( '#modal, #bg-modal' ).fadeOut();
        });
        if (window.location.hash == '#show-modal') {
            showModal();
        }
    });

关于javascript - 在其他页面打开 jQuery Fancybox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16725746/

相关文章:

javascript - Ajax 'Syntax Error: unexpected token <'/'xhr.status 200'

java - 是否可以关闭 JTable 中的自动换行?

javascript - Node JS Express 所有请求显示 404

javascript - 无法在 iOS 的 Webview 中的 html 文本框中写入文本

javascript - 获取 JavaScript 数组中的所有唯一值(删除重复值)

javascript - jQuery 面板 slider 通过单击按钮打开但不会关闭

javascript - 如何通过单击 v-list 项 vue + vuetify 来选择 v-radio

javascript - 想要一个可用于显示 map (不是实际 map )的插件

javascript - 显示可点击的网格

python - BeautifulSoup:从 html 获取 css 类