【发布时间】:2016-01-02 03:55:15
【问题描述】:
我正在尝试构建选项卡式面板,用户可以在刷新、更新等之后保留在当前选项卡上。因此,我正在尝试将此脚本作为选项卡式面板应用到我的网站,但无法弄清楚是什么原因语法错误。几天来,我一直在尝试解决有关标签的问题,但似乎可以解决。顺便说一句,我不使用 cookie 和 jquery。我不使用 cookie,因为我的朋友(我的客户)不在他们的终端上使用 cookie。其次,我不使用 jquery(即使它更好)我只喜欢 php。请帮忙谢谢。
<?php
$('ul.tabs').each(function(){
// For each set of tabs, we want to keep track of
// which tab is active and its associated content
var $active, $content, $links = $(this).find('a');
// If the location.hash matches one of the links, use that as the active tab.
// If no match is found, use the first link as the initial active tab.
$active = $($links.filter('[href="'+location.hash+'"]')[0] || $links[0]);
$active.addClass('active');
$content = $($active[0].hash);
// Hide the remaining content
$links.not($active).each(function () {
$(this.hash).hide();
});
// Bind the click event handler
$(this).on('click', 'a', function(e){
// Make the old tab inactive.
$active.removeClass('active');
$content.hide();
// Update the variables with the new link and content
$active = $(this);
$content = $(this.hash);
// Make the tab active.
$active.addClass('active');
$content.show();
// Prevent the anchor's default click action
e.preventDefault();
});
}); ?>
<html>
<head>
</head>
<body>
<ul class='tabs'>
<li><a href='#tab1'>Tab 1</a></li>
<li><a href='#tab2'>Tab 2</a></li>
<li><a href='#tab3'>Tab 3</a></li>
</ul>
<div id='tab1'>
<p>Hi, this is the first tab.</p>
</div>
<div id='tab2'>
<p>This is the 2nd tab.</p>
</div>
<div id='tab3'>
<p>And this is the 3rd tab.</p>
</div>
</body>
</html>
【问题讨论】:
-
嗯,你在 PHP 中运行 JS,。因此,错误。这完全是两种不同的动物。
-
想看魔术吗?将
<?php替换为<script>,将?>替换为</script>;-) -
这是 all jQuery。 对拉尔夫? @Fred-ii-
-
Si signore Sam @JayBlanchard 嘿……你在这干什么?啊,我敢打赌是一部深夜电影。关于 Wile E. 获得 Road Runner 的那个?
-
10-4 拉尔夫! @Fred-ii-
标签: javascript php