jQuery实现星星评分功能
一、这是我做的调查问卷中的一个功能。(第三方MVC框架)
二、功能说明:1、用户点击星星,将值放到隐藏域中。2、用户可以重新点击星星修改回答。
前台JS代码:
<script type="text/javascript">
//鼠标点击
function picClick(obj) {
var hid = $(obj).parent().find("input[type='hidden']"); //赋值
hid.val($(obj).attr("val"));
hid.attr("num", $(obj).attr("num"));
hid.attr("title", $(obj).attr("title"));
} //鼠标移入
function picMouseOver(obj) {
$(obj).parent().find("img").attr("src", $(obj).attr("src1")); //全部置灰 //设置高亮图片
var currentNum = $(obj).attr("num");
for (var i = 0; i < currentNum; i++) {
$(obj).parent().find("img:eq(" + i + ")").attr("src", $(obj).attr("src2"));
} //显示文本
$(obj).parent().find("#spanResult").text($(obj).attr("title"));
} //鼠标移出
function picMouseOut(obj) {
$(obj).parent().find("img").attr("src", $(obj).attr("src1")); //全部置灰
$(obj).parent().find("#spanResult").text(""); //显示文本 var hid = $(obj).parent().find("input[type='hidden']");
if (hid.val()) {
//设置高亮图片
var currentNum = hid.attr("num");
for (var i = 0; i < currentNum; i++) {
$(obj).parent().find("img:eq(" + i + ")").attr("src", $(obj).attr("src2"));
} //显示文本
$(obj).parent().find("#spanResult").text(hid.attr("title"));
}
}
</script>
Controller代码:
#region 创建单选图片控件
/// <summary>
/// 创建单选图片控件
/// </summary>
/// <param name="title">标题</param>
/// <param name="list">选项</param>
/// <param name="num">题号</param>
/// <param name="evaItemId">指标ID</param>
/// <param name="picUrl">图片URL</param>
/// <param name="edu_EvaluationRecordList">答题集合</param>
/// <param name="disabled">是否可编辑</param>
public static string CreatePicGroup(string title, List<Edu_CodeValue> list, int num, int evaItemId, string picUrl, List<Edu_EvaluationRecord> edu_EvaluationRecordList, bool disabled)
{
string[] picUrlArray = picUrl.Split('|');
string pic1 = "";
string pic2 = "";
if (picUrlArray.Length >= )
{
pic1 = picUrlArray[];
pic2 = picUrlArray[];
}
else if (picUrlArray.Length >= )
{
pic1 = picUrlArray[];
pic2 = picUrlArray[];
}
else { } StringBuilder sb = new StringBuilder();
sb.Append("<div style='margin-top:10px; margin-bottom:30px; margin-left:5px; margin-right:5px;'>");
sb.Append("<div>" + num.ToString() + "、" + title + "</div>"); string strText = "";
int selIndex = -;
int k = ;
foreach (Edu_CodeValue item in list)
{
k++;
if (edu_EvaluationRecordList != null
&& edu_EvaluationRecordList.Exists(a => a.OptionId == item.Id && a.EvaItem != null && a.EvaItem.Id == evaItemId))
{
selIndex = k;
strText = item.Remarks;
break;
}
} sb.Append("<div style='margin-top:5px; margin-left:10px;'>");
int i = ;
foreach (Edu_CodeValue item in list)
{
i++; string strCheckPic = pic1;
if (selIndex != - && i <= selIndex)
{
strCheckPic = pic2;
} if (!disabled)
{
sb.Append("<img num='" + i + "' alt='" + item.Remarks
+ "' title='" + item.Remarks + "' val='" + item.Val
+ "' src='" + strCheckPic + "' src1='" + pic1 + "' src2='" + pic2
+ "' style='cursor:pointer;'"
+ " onclick='picClick(this)' onmouseover='picMouseOver(this)' onmouseout='picMouseOut(this)'/>");
}
else
{
sb.Append("<img alt='" + item.Val + "' src='" + strCheckPic + "' style='margin-left:3px;' />");
}
}
sb.Append("<span id='spanResult' style='margin-left:10px;'>" + strText + "</span>");
sb.Append("<input name='" + evaItemId + "' type='hidden' num='' title='' />");
sb.Append("</div>"); sb.Append("</div>"); return sb.ToString();
}
#endregion
效果图:

jQuery实现星星评分功能的更多相关文章
- jquery--实现类似淘宝星星评分功能
- 不正之处,欢迎指正.^-^.好绕的话 贴码.html <body> <div id="div"> <ul> <li>☆< ...
- vue2.0实现前端星星评分功能组件
<template id="pingJia"> <div> <ul> <li :class="{li1:1,bg1:index% ...
- HTML5商城开发三 jquery 星星评分插件
展示:
- 微信小程序——星星评分
先来个效果图镇楼: 实现原理: 1.循环需要评分的列表,判断它的分数 与 当前星星索引的大小: 2.点击,获取星星对应的分数,让星星高亮. 代码: star.wxml: <view class= ...
- jQuery动态星级评分效果实现方法
本文实例讲述了jQuery动态星级评分效果实现方法.分享给大家供大家参考.具体如下: 这里的jQuery星级评分代码,是大家都很喜欢的功能,目前广泛应用,本星级评分加入了动画效果,注意,如果要真正实现 ...
- 手动实现jQuery Tools里面tab功能
平时开发中用的Javascript类库都是jQuery,用到插件或者第三方类库能从jQuery Tools里面找到,基本不用其他的.当然有时同事喜欢使用jQuery UI里面的插件.并且jQuery ...
- jquery 回车切换 tab功能
挺有趣的,Jquery 回车切换tab功能的实现哦 <html> <head><!--jquery库.js--></head> <body> ...
- jQuery动态五星评分
效果 css .star ul, .star li { list-style: none; } .star { position: relative; width: 600px; height: 24 ...
- iOS评分功能、APP中打开其他应用程序
1.评分功能 iOS中评分支持功能开发非常简单. NSString *str = [NSString stringWithFormat: @"itms-apps://itunes.apple ...
随机推荐
- GitHub 优秀的 Android 开源项目(转)
今天查找资源时看到的一篇文章,总结了很多实用资源,十分感谢原作者分享. 转自:http://blog.csdn.net/shulianghan/article/details/18046021 主要介 ...
- C# inline-hook / api-hook
我查阅了一下相关C#方面的资料,却没有发现有提供过关于api-hook方面的资 料包括应用库由此本人编写一套inline-hook的库用于支持x64.x86上的基于在 clr的公共语言,如: c#.c ...
- UiAutomator源代码分析之UiAutomatorBridge框架
上一篇文章<UIAutomator源代码分析之启动和执行>我们描写叙述了uitautomator从命令行执行到载入測试用例执行測试的整个流程.过程中我们也描写叙述了UiAutomatorB ...
- ecshop退出登录会清空购物车的bug优化,最完美解决方法
ecshop退出登陆后,会清空购物车,大家都应该知道有这样的勉强算bug的问题. 网上类似的教程相当多,但都有问题,说句不好听的,算是引新手入歧途! 总结网上方法如下: 1.修改init.php,把s ...
- Three levels at which any machine carrying out an Information-Processing task must be understood
1. Computational theory What is the goal of computation, why is it appropriate, and what is the logi ...
- android: adapter getView(position==0) was invoked many times.
this is a big problem for me. i follow the solutions that i searched from the internet: modify the ...
- Swift: 深入理解Core Animation(一)
如果想在底层做一些改变,想实现一些特别的动画,这时除了学习Core Animation之外,别无选择. 最近在看<iOS Core Animation:Advanced Techniques&g ...
- window_x64微信小程序环境搭建
所需文件地址如下: http://pan.baidu.com/s/1nv0IHhn(ylk7) 1.下载微信开发工具0.7.0_x64 安装完成后,打开程序,进行微信扫码登录 2.下载微信开发工具 ...
- 使用SQL Server 2014 In-Memory 内存数据库时需要注意的地方
转载: http://www.infoq.com/cn/articles/sql-server-2014-memory-database http://www.cnblogs.com/Amaranth ...
- Hadoop 2.4.1 登录认证配置小结
1.简单模式 这种模式,配置简单,使用简单. core-site.xml添加 <property> <name>hadoop.security.authorization< ...