HTML-点击收藏功能模块
先上效果图:
功能简单:
附上源码以及注解
<div class="info-attribute" id="collect">
<input value="${userId}" type="hidden" class="userId"> <input
value="${orderId}" type="hidden" class="orderId"> <input
value="${type}" type="hidden" class="type">
<span style="float: right;" class="hello1">
<img style="width:22px;height:22px;" data-collect="${flag==1?true:false}" src="${base}/static/front/img/collect-${flag==1?1:0}.png" />
</span>
</div>
userId和orderId、type作为隐藏字段传入
所以在进入详细界面的时候,首先判断从Controller层传进来的变量flag,下面给出flag变量标志判定条件
Map m = myCollectService.getInfo(orderId, commentType, userId);
System.out.println(m);
int index;
// request.setAttribute("flag", );
if (m != null) {
System.out.println("you");
index = 1;
} else {
index = 0;
System.out.println("meiyou");
}
request.setAttribute("flag", index);
getInfo方法:
public Map getInfo(long order_id, int type, long userId)
{
String sql = "SELECT * FROM t_collect WHERE user_id = ? " +
"AND type = ? AND order_id = ?";
return baseDao.jdbcTemplate.findUniqueMapByArray(sql, userId,type,order_id);
}
通过界面传进来的三个参数来查找collect表是否存在此条记录
对应的点击事件触发:
public int addMyCollect(long userId, long orderId, int type
) throws Exception {
//SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
//System.out.println(df.format(new Date()));// new Date()为获取当前系统时间
String sql = "INSERT INTO t_collect(user_id,type,order_id) "
+ " values(?,?,?)";
return baseDao.jdbcTemplate.executeArray(sql, userId, type,orderId
/*df.format(new Date())*/);
}
public int deleteMyCollect(long userId, long orderId, int type
) throws Exception {
String sql = "DELETE from t_collect WHERE " +
"user_id = ? AND order_id = ? AND type = ?";
return baseDao.jdbcTemplate.executeArray(sql, userId, orderId,
type);
}
这样就完成了链接数据库修改收藏记录操作
后面,在界面上,可以通过ajax,来控制图片变换,图片变换之后,提交post请求,执行对应方法
<script type="text/javascript">
$(document).ready(
function() {
$("#collect").click(
function() { var flag = $(this).find("img").attr("data-collect"); var orderId = $(this).find(".orderId").val();
var type = $(this).find(".type").val();
var userId = $(this).find(".userId").val();
var index = 0;
/* if(flag==1){
$(this).find("img").attr("src",
"${base}/static/front/img/collect-1.png");
}
else {
$(this).find("img").attr("src",
"${base}/static/front/img/collect-0.png");
} */ /* alert(type);
alert(orderId); */ if(flag == "false") {
$.post("${base}/front/vip/myCollect/addMyCollect",
{
userId : userId , type : type , orderId : orderId
}, function(data) {
if(data == true) {
updateCollected(true);
}
}); }
else if(flag == "true"){
$.post("${base}/front/vip/myCollect/deleteMyCollect",
{
userId : userId , type : type , orderId : orderId
}, function(data) {
updateCollected(false);
});
}
}); }); function updateCollected(isCollected) {
if (isCollected) {
$("#collect").find("img").attr("src",
"${base}/static/front/img/collect-1.png");
$("#collect").find("img").attr("data-collect", isCollected);
} else {
$("#collect").find("img").attr("src",
"${base}/static/front/img/collect-0.png");
$("#collect").find("img").attr("data-collect", isCollected);
}
}
</script>
HTML-点击收藏功能模块的更多相关文章
- 10天学会phpWeChat——第二天:hello world!我的第一个功能模块
今天我们开始进入<10天学会phpWeChat>系列教程的第二天:创建我的第一个hello world! 功能模块. 1.登录后台,进入 系统设置--自定义模块,如图: 自定义模块参数说明 ...
- 【JAVAWEB学习笔记】网上商城实战5:后台的功能模块
今日任务 完成后台的功能模块 1.1 网上商城的后台功能的实现: 1.1.1 后台的功能的需求: 1.1.1.1 分类管理: [查询所有分类] * 在左侧菜单页面中点击分类管理: * ...
- Java订单功能模块设计与实现
在商城项目中,之前我们介绍了购物车功能模块的实现,商品加入到购物车之后,就是到购物车结算,然后显示购物车的商品列表,点击去结算,然后到了未提交前的订单列表, 点击提交订单后,生成此订单,返回订单的订单 ...
- 文件一键上传、汉字转拼音、excel文件上传下载功能模块的实现
----------------------------------------------------------------------------------------------[版权申明: ...
- RDIFramework.NET V3.3 Web版新增报表管理功能模块-重量级实用功能
功能描述 在RDIFramework.NET V3.3 Web版本新增了全新的报表管理功能模块,非常实用的功能,重量级推荐.主要用于对日常常用的报表做定制展示.可以自动发布到模块(就可授权给指定资源访 ...
- Vue2 实现树形菜单(多级菜单)功能模块
结构示意图 ├── index.html ├── main.js ├── router │ └── index.js # 路由配置文件 ├── components # 组件目录 │ ├── App. ...
- mxonline实战9,我要学习功能块,机构详情展示,收藏功能
对应github地址:第9天 一. 实现我要学习功能
- loushang框架的开发中关于BSP的使用,将写好的功能模块部署到主页界面结构上
前言: 当我们已经开发好相应的模块或者功能的时候,需要将这个功能部署在index主页上作为可点击直接使用的模块,而不是每次需要去浏览对应的url地址. 这时候就需要运用到L5的BSP. 作为刚刚入门l ...
- 18、Django实战第18天:课程机构收藏功能
这里点击"收藏"也是ajax异步操作,我在operation.model.py中创建了一个用户收藏表,其中fav_id字段,如果我们收藏的是课程,那就是课程id,如果收藏的是课程机 ...
随机推荐
- HDU 5166(缺失数查找输出)
HDU 5166 Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Description T ...
- google 论文
从google历年所有论文的汇总来看,TOP5的分别是人工智能和机器学习.算法理论.人机交互与视觉.自然语言处理.机器感知,大家从一个侧面看出goolge research的重点了吧. Google所 ...
- Corn Fields
poj3254:http://poj.org/problem?id=3254 题意:给以n*m的方格,方格中有1或者0,在1的地方可以放置一个物品,但是在物品的上下左右不能有不物品,也可以不放,问你最 ...
- QiQi and Bonds
只有链接:http://sdu.acmclub.com/index.php?app=problem_title&id=961&problem_id=23685 题意:现在有n个QiQi ...
- 工业CF卡与商业CF卡对比
工业CF卡:1.SLC FLASH芯片 .每个区块读写次数为10万次 2.可分区 识别为本地磁盘 3.平均写入技术.ECC自动校验技术 4.完全模拟硬盘引导系统开机,支持长期稳定工作 商业CF卡:1. ...
- android-wear开发之定义布局
Android Wear使用跟手机一样的布局技术,但需要对特定情况进行设计.不要把手机的UI直接照搬过来.更多可查看:Android Wear Design Guidelines 当创建android ...
- 【HDOJ】3088 WORM
状态压缩+BFS. /* 3088 */ #include <iostream> #include <cstdio> #include <cstring> #inc ...
- MongoDB ‘conn’Mongo 对象远程代码执行漏洞
漏洞名称: MongoDB ‘conn’Mongo 对象远程代码执行漏洞 CNNVD编号: CNNVD-201307-497 发布时间: 2013-07-25 更新时间: 2013-07-25 危害等 ...
- zoj3229 Shoot the Bullet(有源汇有上下界的最大流)
题意: 一个屌丝给m个女神拍照,计划拍照n天,每一天屌丝给给定的C个女神拍照,每天拍照数不能超过D张,而且给每个女神i拍照有数量限制[Li,Ri],对于每个女神n天的拍照总和不能少于Gi,如果有解求屌 ...
- CodeForces 587A
题目链接: http://codeforces.com/problemset/problem/587/A 题意: 输入n个数,在这n个数中,寻找有多少个数不能消除掉 消除方法:两个相同的数消除后,生成 ...