Shopify jQuery页面导航 - 按id抓取导航标题

时间:2017-02-04 02:13:35

标签: jquery navigation shopify

我有一个包含很长博客文章的Shopify网站,我正在寻找一种基于H2标签为博客页面模板左侧的文章创建导航的方法。

我使用了一些简单的jQuery和id来链接到页面的不同部分。这是我到目前为止所拥有的。

HTML(模板)

  <div class="col-md-3">
    <ul class="article-nav">
      <li><a href="{{ article.url }}/#g1" alt="" id="title1">Group 1</a></li>
      <li><a href="{{ article.url }}/#g2" alt="" id="title2">Group 2</a></li>
      <li><a href="{{ article.url }}/#g3" alt="" id="title3">Group 3</a></li>
      <li><a href="{{ article.url }}/#g4" alt="" id="title4">Group 4</a></li>
    </ul>
  </div>
  <div class="col-md-9">
    {{ article.content }}
  </div>

现在这里是博客文章中的代码

<h2 id="g1">This is my first title</h2>
<p>Some content ...</p>
<h2 id="g2">This is my second title</h2>
<p>Some content ...</p>
...

这是我必须把它们放在一起的jQuery

var tr1 = $(g1).text();
var tr2 = $(g2).text();
var tr3 = $(g3).text();
var tr4 = $(g4).text();
$(title1).html( tr1 );
$(title2).html( tr2 );
$(title3).html( tr3 );
$(title4).html( tr4 );

我不是javascript或jQuery的专家。有没有办法简化这段代码?看起来我现在写的太多了,可能会收紧。

1 个答案:

答案 0 :(得分:0)

使用jquery:

SELECT tblBOOK.Concat, tblIndustry.[Industry Name],tblIndustry.[Industry Points],
tblOwner1.Primary, tblOwner1.Points, tblFILE.Score, tblFILE.Points, tblCARD.Score, 
tblCARD.Points, tblRisk.Factor, tblRisk.Points, 
[Industry Points]+[tblOwner1]![Points]+[tblFILE]![Points]+[tblCARD]![Points]+ 
[tblRisk]![Points] 
AS TotalPoints 

FROM ((((tblBOOK 
LEFT JOIN tblIndustry ON tblBOOK.Industry = tblIndustry.[Industry Name])     
LEFT JOIN tblOwner1 ON tblBOOK.Owner1 = tblOwner1.Primary) 
LEFT JOIN tblFILE ON tblBOOK.CSS = tblFILE.Score) 
LEFT JOIN tblCARD ON tblBOOK.CARD = tblCARD.Score) 
LEFT JOIN tblRisk ON tblBOOK.Risk = tblRisk.Factor;