【发布时间】:2016-05-16 11:46:07
【问题描述】:
我想在我的一个项目中添加“添加到收藏夹/书签”功能,但对此完全空白。
基本上,如果用户想从收藏夹中添加/删除,我会使用引导字形图标来选择它。我做了一些研究,发现 html5 localStorage 概念合适,但无法真正弄清楚它对我的项目的确切工作。如果这里有人可以指导我,那将是一个很大的帮助。
这里是html:
<h1>test</h1>
<table class="'basic">
<tr>
<td><div class="glyphicon glyphicon-star-empty icon bkmark_icon"> </div></td>
<td>A</td>
</tr>
<tr>
<td><div class="glyphicon glyphicon-star-empty icon bkmark_icon"> </div></td>
<td>B</td>
</tr>
<tr>
<td><div class="glyphicon glyphicon-star-empty icon bkmark_icon"> </div></td>
<td>C</td>
</tr>
</table>
<br><button class="btn">You have selected:</button>
由于我不是很了解 jQuery 中 localStorage 的实现,所以没有添加它,但这是 js 文件现在有的:
$(function() {
$(document).on('click', '.bkmark_icon', function(){
$(this).toggleClass('glyphicon-star-empty glyphicon-star');
// localStorage.setItem('display', $(this).is(':visible'));
});
$(document).on('click', '.btn', function(){
var bkmark_item = '<table><tr><td><div class="glyphicon glyphicon-star icon bkmark_icon"></div></td><td>*selected*</td></tr></table>';
$(bkmark_item).insertAfter('h1');
});
});
我确实搜索过它,发现这个堆栈溢出 answer 合适。
我需要什么?
- 当用户点击 glyphicon-star-empty 时,它应该切换到 glyphicon-star 并且相关项目应该添加到 localStorage(即收藏夹)。
- 当用户单击“您已选择:”按钮时,它应该删除表格中的当前内容并仅显示收藏的项目(在同一页面上)并带有取消收藏的选项。
这是fiddle,我正在处理。
【问题讨论】:
标签: javascript jquery css html twitter-bootstrap