简体   繁体   English

后退按钮后切换

[英]Toggle after back button

Hello people i have this code.... 大家好我有这个代码....

<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>

above code is working fine by toggling red color between cells and it also redirects page to "specific location" when clicked on it.please check the demo ,you can observ first the cell goes red color then it will be redirected to google/yahoo/bing ,but now what iam need to do when they come back to by clicking back button /(code what i write) ,specific cell which was selected should still be highlighted with red color.... i reied doing this by session but not exactly.. can any one plzz help me to fix this.... 上面的代码通过在单元格之间切换红色来正常工作,并且当点击它时它还将页面重定向到“特定位置”。请检查演示 ,您可以首先观察单元格变为红色然后它将被重定向到google / yahoo / bing,但现在我们需要做什么,当他们回来时点击后退按钮/(我写的代码),被选中的特定单元格仍然应该用红色突出显示....我依旧通过会话这样做但不是确切..可以任何一个plzz帮助我解决这个问题....

You can do that with $.cookie 你可以用$ .cookie做到这一点

Assign an ID for each line and set cookie, then check that cookie for an available id: 为每一行分配一个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>​

and javascript: 和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');
    }
});

​ You can use plain javascript for cookie, I used that plugin for example . 您可以使用纯JavaScript进行饼干,我使用了插件例子

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

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