2015-02-09 47 views
0

我已經創建了一個包含60多個問題的FAQ頁面,現在我想創建一個鏈接到每個問題,這樣我就可以在我的博客中提供鏈接,並且點擊用戶可以直接登錄該問題必須瀏覽整個FAQ頁面。那麼我如何創建鏈接?我只使用html,css和javascript。那麼有人可以幫我解決這個問題嗎?如何爲我的頁面創建永久鏈接?

+1

研究「錨鏈接」。 – CBroe 2015-02-09 11:04:36

回答

0

您可以使用錨點。從W3Schools的

實施例:

添加一個id屬性的任何元素:

<a id="tips">Useful Tips Section</a> 

然後創建到元件的鏈接(有用的提示段):

<a href="#tips">Visit the Useful Tips Section</a> 

或者,創建從另一個頁面到元素的鏈接(有用提示部分):

<a href="http://www.w3schools.com/html_links.htm#tips">Visit the Useful Tips Section</a> 

http://www.w3schools.com/html/html_links.asp

1

我建議建立在你的FAQ頁面的頂部,這可能已下令例如問題內容部分。

這可以通過創建一個有序列表並列出您的問題來實現。

然後你可以鏈接你的問題,這樣當這個人點擊這個問題時,他會被引導到頁面的確切位置。這可以通過使用錨點來實現,就像Yavor說的那樣。

您首先需要創建一個ID爲每個問題,例如:

<div id="question1">Here is a question</div> 
<div>Here is the answer to the question</div> 

然後在排序菜單,創建一個錨在您答疑解惑相應的問題:

<ul><li><a href="#question1">This will take you to question 1</a></li></ul> 
0

添加以下腳本以平滑滾動

<a href="#question1">1. How to log out?</a><br/> 

<h3 id="question1">1. How to log out?</h3> 
<p>Answer...</p> 

<script> 
    $(function() { 
     $('a[href*=#]:not([href=#])').click(function() { 
      if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) { 
       var target = $(this.hash); 
       target = target.length ? target : $('[name=' + this.hash.slice(1) + ']'); 
       if (target.length) { 
        $('html,body').animate({ 
         scrollTop: target.offset().top - 65 
        }, 1000); 
        return false; 
       } 
      } 
     }); 
    }); 
</script>