从列表中添加/删除项目并更新总数

adding/deleting items from a list and updating the total

本文关键字:更新 删除项目 列表 添加      更新时间:2023-09-26

我正在构建一个类似于购物车的东西,但是将项目添加到候选列表中。

我需要将项目添加到购物车中,然后更新购物车计数并在模态窗口中显示添加的项目(我计划使用Zurb的Reveal插件)。

到目前为止,我已经添加到购物车工作,但我还不能更新计数(不刷新页面)或显示模式。

http://jsfiddle.net/x7Azn/2/

$('a.add-to-shortlist').on('click',function(){  
$.ajax({
  url: $(this).attr('data-href'),
  success: function(data) {     
      verb = data['verb'];
      total_items = data['total_items'];
      alert('item added to shortlist');
  }
});
  // stop event propagation here
 return false;
});

帮助感激。

要更改e.p preventdefault()调用后的文本,请将以下内容放入函数中-

  e.preventDefault();
  $(this).text('remove from list');

try this

$('.item-count')html(total_items );