简体   繁体   English

如何将javascript / jquery函数从一个HTML页面传递到另一HTML页面

[英]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.

相关问题 如何在JavaScript中将值从一个html页面传递到另一个页面? - How to pass value from one html page to another in JavaScript? 如何使用JQuery将数据从一个HTML页面传递到另一HTML页面? - How to pass data from one HTML page to another HTML page using JQuery? 如何将 javascript 变量值从一个 html 页面传递到另一个 html 页面? - How to pass the javascript variable value from one html page to the another html page? 如何使用javascript将值从一个html页面传递到另一个html页面 - How can I pass values from one html page to another html page using javascript 如何仅使用JavaScript将表单数据从一个HTML页面传递到另一HTML页面? - How do I pass form data from one HTML page to another HTML page using ONLY javascript? 如何将参数从一个页面 function 传递到另一个页面 class function 在 Z9E13B69D1D715A927102ACAAAF14Z - how to pass parameter from one page function to another page class function in Javascript / Node js 如何使用Phonegap中的JavaScript将数据从一个html传递到另一个html页面? - How to pass the data from one html to another html page using JavaScript in Phonegap? 如何将数组从一个HTML传递到另一个HTML页面? - how to pass an array from one html to another html page? 如何将数据从一个页面传递到另一个页面html - How to pass data from one page to another page html 如何在html中将数据从一个页面传递到另一个页面? - How to pass data from one page to another page in html?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM