1

我想知道你是否能给我一些关于如何做到这一点的想法。我们要做的是直接链接到我们的常见问题页面中的问题。目前,我们的常见问题解答问题正在通过 jQuery 隐藏,如下所示:

$(document).ready(function() {
    $('.answer').each(function() {
        $(this).css("display", "none");
    });
    $('.question').click(function() {
        $(this).next('.answer').slideToggle("fast")
        return false;
    });
});

我们想链接到一个特定的问题,但扩展了该问题。

4

3 回答 3

3

您可以使用 url 中的哈希值来标记要在 ready 函数中显示的常见问题。使用将其连接到哈希值的 id 标记每个常见问题解答。通过访问散列值window.location.hash,然后仅显示与散列值匹配的常见问题解答。

例子:

http://mypage.com/faq.html#faq1 将连接到您的 id="faq1" 标记的常见问题解答

于 2011-11-18T20:49:10.553 回答
3

我会将 URL 中的 quetsion 部分作为哈希传递,例如 url/faq.html#question1

然后使用一些javascript,您可以检查哈希,然后将用户滚动到该部分并切换幻灯片。

$(function(){
  if(window.location.hash) {
    // Fragment exists
    // use hash value to match an attribute in the question.
    // scroll to Q/A and toggle.
  }   
});
于 2011-11-18T20:50:48.073 回答
2

为每个答案设置一个 ID 或a name,如果设置了哈希标签,则使用 JS 检查页面加载,并相应地打开问题:

(function(hash){
    if (hash !== undefined && hash.substring(0,1) === "#") {
     $(hash).slideToggle("fast"); 
    }  
})(window.location.hash);

示例:http: //jsfiddle.net/wSRyP/

您可以使用#hashtag 链接到它们:

http://fiddle.jshell.net/78Udw/show/light/

于 2011-11-18T20:51:18.273 回答