dssj88098 2016-09-12 18:52
浏览 117

Localstorage一直在重置

I am calling data from mysql in rows, and each ID is placed in a seperate div. Once a customer clicks on one of these div's (url) the div should remove itself and place itself in the "seen" tab. I do this by removing and adding another class.

This works perfectly, but if I am now going for example ID 15 then this one is removing itself from new to 'seen'. But the first one is resetting itself and moves to 'new' again. How can I make sure every time I click on a new url in the row it collects another one in the 'seen' tab?

PHP:

<?php while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
// output data of each row
$idselection = $row["entryId"];
    echo "<div class='one-block-info' style='width: 33%; float: left; margin-top: 10px; margin-bottom: 10px; text-align: center; border: 1px solid black;'><div class='hide_div' style='font-size: 17px; color: #6A8F3B;'><br /><a class='tag-link new' style='color: rgb(106, 143, 59);' href='/offerte-formulier?id=". $idselection ."' target='_self'>ID:<span class='empty_span'> " . $idselection . "</span></a></div>
    <div class='hide_div'><br />Keuken Type:<span class='empty_span'> " . $row["stijlkeuken"] . "</span></div>
    <div class='hide_div' style='padding-bottom: 10px;'><br />Voornaam & Achternaam:<span class='empty_span'> " . $row["firstname"] . " " . $row["lastname"] . "</span></div></div>";
} ?>

Javascript:

$(document).ready(function() {
  $("a.tag-link.new").click(function() {
    var pid = $(this);

    $(pid).removeClass("new");
    $(pid).addClass("active");
    localStorage.setItem("selectedolditem", $(pid).text());
  });

  var selectedolditem = localStorage.getItem('selectedolditem');

  if (selectedolditem !== null) {

    $("a:contains('" + selectedolditem + "')").removeClass("new");
    $("a:contains('" + selectedolditem + "')").addClass("active");
  }
});

So I need to make sure that every row I click should move to 'seen' tab without another one coming back. Thanks all

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条
    • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
    • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
    • ¥15 perl MISA分析p3_in脚本出错
    • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
    • ¥15 ubuntu虚拟机打包apk错误
    • ¥199 rust编程架构设计的方案 有偿
    • ¥15 回答4f系统的像差计算