如何将唯一的 url 参数分配给常见问题解答



我有几个问题需要常见问题解答。常见问题解答的编码方式是,单击问题的活动面板时会展开,但默认情况下会打开第一个问题。现在,我想使每个面板在单击时都具有其唯一的URL。

<div class="row faq_links">
<h1 class="faq-header">Frequently Asked Questions</h1>
<div id="accordion" class="faq-column">
<div id="faq1" class="panel tabcontent">
<p class="header">What is ....?</p>
<p class="body">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s</p>
</div>
<div id="faq2" class="panel tabcontent" onClick="goTo(this)">
<p class="header">How does ... Work?</p>
<p class="body">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s</p>
</div>
<div id="faq3" class="panel tabcontent">
<p class="header">Who are ...?</p>
<p class="body">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s</p>
</div>
</div>

function goTo (panel) {
var url, faqs, para
url = window.loaction;
faqs = faq.getElementsByClassName("tabcontent");
for (i = 0; i < faqs.length; i++) {
para = faqs[i].getElementsByTagName("p")[0];
if (url == panel) {
url.replace(url + id);
}
}

我想使每个面板在单击时都有其唯一的URL,但我被卡住了。

您的代码中似乎有拼写错误

url = window.loaction;

更改为window.location

此外,window.location 是一个对象,永远不会等于panel,所以条件总是 false。 并且id未定义,并且会抛出错误,

您可能正在寻找类似的东西

hash = window.location.hash;
if(hash!=panel) //assuming panel is the hash(that is, id of the clicked div)
window.location.hash = panel;

最新更新