Jquery在会话存储中从文本中找到li,然后获取数据值

时间:2016-11-15 17:21:56

标签: jquery list drop-down-menu html-lists

我需要根据会话存储中的文本在列表中查找文本,然后获取该特定列表项的数据值并将其设置为会话存储。

if(sessionStorage.getItem('thismodel')){
              var obj1 = JSON.parse(sessionStorage.thisyear);
              $("#vehic_sel_year-label-perf em").html(obj1);
              var obj2 = $('#vehic_sel_year-perf li').find(obj1).data('value');
              sessionStorage.setItem('model1', obj2);
        }

我觉得这不应该太难,但我无法理解。任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:0)

使用jQuery非常简单。

var obj1 = 'Text 2';
var obj2 = $('li:contains("' + obj1 + '")', '#vehic_sel_year-perf').data('value');
$('#found').html(obj2);