[英]How to pass a javascript/jquery function from one html page to another
I have this page articles 我有此页文章
In this page i have nav links on the left, and content loading on the right. 在此页面中,我在左侧有导航链接,在右侧有内容加载。
function showonlyone(thechosenone) {
$('div[name|="newboxes"]').each(function(index) {
if ($(this).attr("id") == thechosenone) {
$(this).show(200);
}
else {
$(this).hide(600);
}
});
}
my nav looks like this 我的导航看起来像这样
<ul>
<li><a id="myHeader1" href="javascript:showonlyone('articles');" >ARTICLES</a></li>
<li><a id="myHeader1" href="javascript:showonlyone('whitepapers');" >WHITE PAPERS</a></li>
<li><a id="myHeader1" href="javascript:showonlyone('brochures');" >BROCHURES</a></li>
</ul>
and my content is in div like the following 我的内容在div中,如下所示
<div id="articles" name="newboxes" style="display:none;">
<div id="whitepapers" name="newboxes" style="display:none;">
<div id="brochures" name="newboxes" style="display:none;">
Basically this page, is an interior page. 基本上,此页面是内部页面。 I have a home page, that i would like to have links to each section on, so the section i want shows up already so user doesn't have to click again.
我有一个主页,我希望每个部分都有链接,因此我要显示的部分已经显示出来,因此用户不必再次单击。
Any idea how i do this? 知道我该怎么做吗?
Thank you for any help, and I apologize if i'm not using correct terminology. 谢谢您的帮助,对于我使用的术语不正确,我深表歉意。
if I well understood your question, on page "articles" just call showonlyone
function 如果我很了解您的问题,请在“文章”页面上调用
showonlyone
函数
$(function() { // DOMready
showonlyone('articles');
});
and repeat this code for every internal page, changing the parameter 并对每个内部页面重复此代码,更改参数
going by what i understand from your question is that.. 我从你的问题中了解到的是..
u have links on home page.. 您在首页上有链接。
when user clicks these links you want that particular section to be already opened when the interior page opens 当用户单击这些链接时,您希望在打开内部页面时已经打开了该特定部分
like when user click "articles" then in the interior page the articles div should be visible 例如当用户单击“文章”,然后在内部页面中, 文章div应该可见
for this you will have to use hash tags in the following manner 为此,您将必须以以下方式使用哈希标签
on your home page.. provide the links with a hash tag like this 在您的主页上..为链接提供一个像这样的哈希标签
http://agencystudy.com/eic/microsites/microsites-02/articles.html#articles
then in your interior page in document ready event 然后在您的内部页面中准备文档事件
$(document).ready(function(){
$(window.location.hash).show(200);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.