繁体   English   中英

后退按钮后切换

[英]Toggle after back button

大家好我有这个代码....

<html>
<head>
<script class="jsbin" src="http://ajax.googleapis.com /ajax/libs/jquery/1/jquery.min.js"></script>
<script>
$(function(){
    $(".mytableCol3").click(function(){
        $(this).addClass("on").parent().siblings("tr").find("td").removeClass("on");
    });
});
</script>
<style>
    .on { background-color:red; color:#ffffff; }
</style>
</head>
<body>

<table class="mytable" border=1>
  <tbody>
    <tr>
      <td class="mytableCol3"><a href="google.com">google</a></td>
    </tr>
    <tr>
      <td class="mytableCol3"><a href="yahoo.com">yahoo</a></td>
    </tr>
    <tr>
      <td class="mytableCol3"><a href="bing.com">bing</a></td>
    </tr>
  </tbody>
</table>
<table class="mytable" border=1>
</body>
</html>

上面的代码通过在单元格之间切换红色来正常工作,并且当点击它时它还将页面重定向到“特定位置”。请检查演示 ,您可以首先观察单元格变为红色然后它将被重定向到google / yahoo / bing,但现在我们需要做什么,当他们回来时点击后退按钮/(我写的代码),被选中的特定单元格仍然应该用红色突出显示....我依旧通过会话这样做但不是确切..可以任何一个plzz帮助我解决这个问题....

你可以用$ .cookie做到这一点

为每一行分配一个ID并设置cookie,然后检查该cookie是否有可用的id:

<table class="mytable" border=1>
    <tbody>
        <tr>
            <td class="mytableCol3" id="google"><a href="http://google.com">google</a></td>
        </tr>
        <tr>
            <td class="mytableCol3" id="yahoo"><a href="http://yahoo.com">yahoo</a></td>
        </tr>
        <tr>
            <td class="mytableCol3" id="bing"><a href="http://bing.com">bing</a></td>
        </tr>
    </tbody>
</table>​

和javascript:

$(function(){
    $(".mytableCol3").click(function(){
        $(this).addClass("on").parent().siblings("tr").find("td").removeClass("on");
        $.cookie('clicked', $(this).attr('id'));
    });

    if($('#'+$.cookie('clicked'))){
        $('#'+$.cookie('clicked')).addClass('on');
    }
});

您可以使用纯JavaScript进行饼干,我使用了插件例子

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM