【问题标题】:Local storage taking even index?本地存储占用索引?
【发布时间】:2023-03-04 00:33:01
【问题描述】:

这是我的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 中生成 evenvisited = true

 visited0 = true
 visited2 = true
 visited4 = true

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

【问题讨论】:

  • 您的标记错误。您有 &lt;tr&gt; 而不是 &lt;/tr&gt;,这意味着您每隔一次添加一个空行。

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


【解决方案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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-05
    • 2023-03-29
    • 2014-09-11
    • 1970-01-01
    • 1970-01-01
    • 2012-05-05
    • 1970-01-01
    • 2020-03-03
    相关资源
    最近更新 更多