Jquery 如何在单击事件时存储值 var btnlist=”“; $(“#divPopup”)。在(“单击”,“li”,函数(){ var$this=$(this); //获取currect id并替换为right var newId=$this.attr('Id')。替换(“左”、“右”) //检查图像是否为非真 if($('#'+newId).find('img').attr('class')!='checkImage'){ $this.toggleClass(“选定”); if($this.attr('class')=“selected”){ btnlist。 $(“#”+newId).show();/

Jquery 如何在单击事件时存储值 var btnlist=”“; $(“#divPopup”)。在(“单击”,“li”,函数(){ var$this=$(this); //获取currect id并替换为right var newId=$this.attr('Id')。替换(“左”、“右”) //检查图像是否为非真 if($('#'+newId).find('img').attr('class')!='checkImage'){ $this.toggleClass(“选定”); if($this.attr('class')=“selected”){ btnlist。 $(“#”+newId).show();/,jquery,html,Jquery,Html,sessionStorage或localStorage是键/值对,您只需执行以下操作: var btnlist=""; $("#divPopup").on("click", "li", function () { var $this = $(this); // get currect id an replace with right var newId = $this.attr('Id').replace("Left", "Right") // check if

sessionStorage
localStorage
是键/值对,您只需执行以下操作:

var btnlist="";
$("#divPopup").on("click", "li", function () {
    var $this = $(this);
    // get currect id an replace with right
    var newId = $this.attr('Id').replace("Left", "Right")
    // check if the image is not for True
    if ($('#' + newId).find('img').attr('class') != 'checkImage') {
        $this.toggleClass("selected");
        if ($this.attr('class') == "selected") {
            btnlist.
            $('#' + newId).show(); // <== i want to store Newid each time when.show() method ex
        }
        else {
            var newId = $this.attr('Id').replace("Left", "Right")
            $('#' + newId).hide();
        }
    }
});
您可能需要检查浏览器是否支持以下功能:

sessionStorage.newId = newId;
更新


sessionStorage
localStorage
不支持数组,但您可以将数据存储为json字符串:

if(typeofsessionStorage)!=="undefined")
{
  // storage supported
}
你可以用

从文件:

amplify.store是各种持久客户端存储系统的包装器。amplify.store支持IE 5+、Firefox 2+、Safari 4+、Chrome、Opera 10.5+、iPhone 2+、Android 2+,并提供一致的API来处理跨浏览器存储

示例用法:

sessionStorage.newIds = JSON.stringify([1, 2, 3]);
var ids = JSON.parse(sessionStorage.newIds);
编辑

要在HTML5会话存储中存储值,您应该查看以下链接:

编辑-2

我创建了一个fiddle,您可以在其中看到访问所有li项的代码以及如何保存单击的项


我将使用
$this.attr('class')==“selected”
,而不是
$this.is('.selected')
$this.hasClass('selected')
你可能想在你的问题中添加
HTML5
javascript
标记。也许你想解释一下你在“存储”时想要实现什么btnlist中的某些内容-可能有比您想象的更好的方法来实现您想要的结果。我的问题已更新。对不起,但我仍然不明白,您是否要在
会话存储中存储数组?
?是的,我想要所有可见的li元素,可能是数组选项检查我编辑过的答案,不幸的是,看起来这使它成为了一个副本,对吗?谢谢你的回复:),但我不是在寻找存储,我想要所有可见的项目,并将它们存储在html 5会话存储中,但我真的不是在寻找存储部分的方式,当我点击时,我需要ID列表,仅此而已,先生:(@NestorC)请编辑您的问题,并明确定义您的实际内容want@NestorC请检查更新的答案
(编辑-2)
,我根据您编辑的理解制作了一把小提琴,希望这次能有所帮助
amplify.store(key, value)       // => store the value on the given key

var value = amplify.store(key); // => extract the value on the given key