jquery更改在不同的html页面上执行

jquery更改在不同的html页面上执行,jquery,html,css,Jquery,Html,Css,有没有办法让一个html更改上的链接在单独的html页面中激活jquery更改?我认为这个问题是相关的,但我不完全理解 当我点击“page1.html”中的链接时,我想打开链接并对“page2.html”进行更改 示例: <a href="page2.html#services" class="tab-link">Link to Services</a> <a href="page2.html#contact" class="tab-link">Link to

有没有办法让一个html更改上的链接在单独的html页面中激活jquery更改?我认为这个问题是相关的,但我不完全理解

当我点击“page1.html”中的链接时,我想打开链接并对“page2.html”进行更改

示例:

<a href="page2.html#services" class="tab-link">Link to Services</a>
<a href="page2.html#contact" class="tab-link">Link to Contact</a>
<!-- I set the ID's to match the hash on the above links -->
<div id="services" class="tab-content">
    <h3>Services</h3>
</div>
<div id="contact" class="tab-content">
    <h3>Contact</h3>
</div>
页面1.html

<a href="page2.html#about" class="tab-link">Link to Services</a>

第1页:

<a href="page2.html#services" class="tab-link">Link to Services</a>
<a href="page2.html#contact" class="tab-link">Link to Contact</a>
<!-- I set the ID's to match the hash on the above links -->
<div id="services" class="tab-content">
    <h3>Services</h3>
</div>
<div id="contact" class="tab-content">
    <h3>Contact</h3>
</div>
第2页的JS:

$(document).ready(function(){
    // window.location.hash returns the '#...' part of the page URL
    // which from the html I provided, would be #services or #contact.
    // We check to make sure there is one first, and then set your 'active' class
    if(window.location.hash){
        var tabID = window.location.hash;
        $(tabID).addClass('active'); 
    }
});

在浏览器中使用jQuery等语言时,JavaScript仅适用于浏览器中当前加载的页面。刷新、重新加载或加载页面后,不会出现任何更改。@Djave虽然为true,但这与问题或答案无关