需要使用jQuery标签插件,寻求帮助。

3
我正在使用以下代码作为选项卡插件:
//When page loads...
 $("#searchbox .tab_content").hide(); //Hide all content
 $("#searchbox ul.tabs li:first").addClass("active").show(); //Activate first tab
 $("#searchbox .tab_content:first").show(); //Show first tab content
//alert($("ul.tabs li:last").find("a").attr("href"));
 //On Click Event
 $("#searchbox ul.tabs li").click(function() {

  $("#searchbox ul.tabs li").removeClass("active"); //Remove any "active" class
  $(this).addClass("active"); //Add "active" class to selected tab
  $("#searchbox .tab_content").hide(); //Hide all tab content

  var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
  $(activeTab).fadeIn(); //Fade in the active ID content
  return false;
 });

我的HTML页面包含4个列表项作为菜单。当页面刷新时,它总是会加载第一个元素的内容,如代码中所示。每个li链接到具有各自表单的div。如果我在action表单中调用同一页面,如何加载相应的内容。这意味着如果我提交了搜索租金表单,那么当页面刷新时,它应该显示搜索租金容器,而不是li:first。

1
你能否编辑一下标题,使其更具体地描述你的问题?这里有很多需要在 JQuery 方面得到帮助的人 :-) - psmears
不是我的领域,但似乎你应该查看 cookies。 - Mantar
1个回答

1

您可以在搜索表单中添加一个隐藏字段,其中包含有关当前打开标签的信息,并在发布后使用该信息在 li 元素上设置正确的类。

将您的表单更改如下:

<form method="post">
  <input type="hidden" name="activetab" value="" />
  ...
</form>

然后像这样,您可以使用li元素的id来知道哪个选项卡是活动状态:

$("#searchbox ul.tabs li").click(function() {
    $("input[name=activetab]").val($(this).attr("id"));
});

在提交表单后,如果您使用PHP,可以这样做:

foreach($tab_id_array as $tab_id) { ?>
<li class="<?= ($_POST["activetab"]==$tab_id) ? "active" : "" ?>"><?= $tabcontent ?></li>
<? } ?>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接