本地存储采用均值指数?

时间:2014-04-12 17:16:56

标签: javascript jquery ruby-on-rails-4 local-storage

这是我的HTML:

  <table>
        <thead>
            <tr style = 'background-color: white'>
                <th> <i class="fa fa-male"></i> Name </th>
                <th><i class="fa fa-bars"></i> Particular</th>
                <th><i class="fa fa-envelope-o"></i>Unit</th>
                <th><i class="fa fa-map-marker"></i>Quantity</th>
                <th><i class="fa fa-phone"></i>From</th>
                <th><i class="fa fa-phone"></i>Cost</th>
                 <th><i class="fa fa-phone"></i>Total</th>
                <th><i class="fa fa-phone"></i>TAKE actions</th>
            </tr>
        </thead>
        <tbody>

              <tr>
                <td>Mobile</td>
                <td>nokia rerihh</td>
                <td>LVP</td>
                <td>77</td>
                <td>Snehpandya</td>
                <td>777</td>
                <td>59829</td>
                <td>
                    <form action="/requisitions/5" class="button_to" method="get"><div><input class="po" data-confirm="Really wants to generate Po?" type="submit" value="Send for approval -&gt;" /></div></form>

                </td>
             <tr>
              <tr>
                <td>Table</td>
                <td>sneh is a good boy</td>
                <td>LVP</td>
                <td>7</td>
                <td>Snehpandya</td>
                <td>78</td>
                <td>546</td>
                <td>
                    <form action="/requisitions/6" class="button_to" method="get"><div><input class="po" data-confirm="Really wants to generate Po?" type="submit" value="Send for approval -&gt;" /></div></form>

                </td>
             <tr>
              <tr>
                <td>Mobile</td>
                <td>jskfbhksjfkjfgweh</td>
                <td>LVP</td>
                <td>7</td>
                <td>Anil</td>
                <td>77</td>
                <td>539</td>
                <td>
                    <form action="/requisitions/7" class="button_to" method="get"><div><input class="po" data-confirm="Really wants to generate Po?" type="submit" value="Send for approval -&gt;" /></div></form>

                </td>
             <tr>
        </tbody>
    </table>

在我的Jquery中;

$(document).ready(function(){

 $(".po").click(function(e){

    localStorage.setItem("visited" + $(this).closest("tr").index(), true);
    $(this).css("color", "red"); // visited
});

for(var i = 0, len = $(".po").length; i < len; i++){

    if(localStorage.getItem("visited" + i)){

        $(".po:eq(" + i + ")").css("color", "yellow"); // visited
    }else
    {
        $(".po:eq(" + i + ")").css("color", "black"); // not visited
    }
}
});

问题是它只会在crome 中生成偶数被访问的= true 即

 visited0 = true
 visited2 = true
 visited4 = true

我想让它正常1,2,3,4,我错了吗?

1 个答案:

答案 0 :(得分:1)

您没有关闭行。

<tr>
                <td>Mobile</td>
                <td>nokia rerihh</td>
                <td>LVP</td>
                <td>77</td>
                <td>Snehpandya</td>
                <td>777</td>
                <td>59829</td>
                <td>
                    <form action="/requisitions/5" class="button_to" method="get"><div><input class="po" data-confirm="Really wants to generate Po?" type="submit" value="Send for approval -&gt;" /></div></form>

                </td>
             <tr>

必须是

<tr>
                <td>Mobile</td>
                <td>nokia rerihh</td>
                <td>LVP</td>
                <td>77</td>
                <td>Snehpandya</td>
                <td>777</td>
                <td>59829</td>
                <td>
                    <form action="/requisitions/5" class="button_to" method="get"><div><input class="po" data-confirm="Really wants to generate Po?" type="submit" value="Send for approval -&gt;" /></div></form>

                </td>
             </tr>