一、这是我做的调查问卷中的一个功能。(第三方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实现星星评分功能的更多相关文章

  1. jquery--实现类似淘宝星星评分功能

    -   不正之处,欢迎指正.^-^.好绕的话 贴码.html <body> <div id="div"> <ul> <li>☆< ...

  2. vue2.0实现前端星星评分功能组件

    <template id="pingJia"> <div> <ul> <li :class="{li1:1,bg1:index% ...

  3. HTML5商城开发三 jquery 星星评分插件

    展示:

  4. 微信小程序——星星评分

    先来个效果图镇楼: 实现原理: 1.循环需要评分的列表,判断它的分数 与 当前星星索引的大小: 2.点击,获取星星对应的分数,让星星高亮. 代码: star.wxml: <view class= ...

  5. jQuery动态星级评分效果实现方法

    本文实例讲述了jQuery动态星级评分效果实现方法.分享给大家供大家参考.具体如下: 这里的jQuery星级评分代码,是大家都很喜欢的功能,目前广泛应用,本星级评分加入了动画效果,注意,如果要真正实现 ...

  6. 手动实现jQuery Tools里面tab功能

    平时开发中用的Javascript类库都是jQuery,用到插件或者第三方类库能从jQuery Tools里面找到,基本不用其他的.当然有时同事喜欢使用jQuery UI里面的插件.并且jQuery ...

  7. jquery 回车切换 tab功能

    挺有趣的,Jquery 回车切换tab功能的实现哦 <html> <head><!--jquery库.js--></head> <body> ...

  8. jQuery动态五星评分

    效果 css .star ul, .star li { list-style: none; } .star { position: relative; width: 600px; height: 24 ...

  9. iOS评分功能、APP中打开其他应用程序

    1.评分功能 iOS中评分支持功能开发非常简单. NSString *str = [NSString stringWithFormat: @"itms-apps://itunes.apple ...

随机推荐

  1. [开发笔记]-MarkDown语法

    马克飞象MarkDown在线编辑器 http://maxiang.info/?basic 1. H1--H6 相应数量的# 2. 底线形式 = H1(最高阶标题)和- H2(第二阶标题) 3. 段落和 ...

  2. Snippet: align a TextView around an image

    A few weeks ago I discovered the Spans on Android,after reading the wonderful post by Flavien Lauren ...

  3. Git + BeyondCompare

    Mac 环境: 1. 安装 BeyondCompare 2. 配置 ~/.gitconfig [diff] tool = bcomp [merge] tool = bcomp [difftool &q ...

  4. Two classes have the same XML type name 排错【转】

    今天遇到一个问题,webservice发布的时候报下面的错误: <strong>Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotati ...

  5. 【C#|.NET】lock(this)其实是个坑

    这里不考虑分布式或者多台负载均衡的情况只考虑单台机器,多台服务器可以使用分布式锁.出于线程安全的原因,很多种场景大家可能看代码中看到lock的出现,尤其是在资金类的处理环节. 但是lock(this) ...

  6. FMDB 版本迁移

    FMDB 版本迁移 安装 1. 通过CocoaPods 在项目根目录创建并编辑 Podfile 内容如下 $ cd /path/to/MyProject $ touch Podfile $ edit ...

  7. 使用Xcode6.1.1打包出现Your account already has a valid iOS Distribution certificate问题

    1.问题描述: 使用客户证书在Xcode6.1.1上进行打包测试,出现如下问题,查看网上也很多类似错误且解决办法各异. 2.我的解决办法: 让客户将开发.发布证书重新revoke掉之后重新创新并给到p ...

  8. 10个你必须掌握的超酷VI命令技巧

    摘要:大部分Linux开发者对vi命令相当熟悉,可是遗憾的是,大部分开发者都只能掌握一些最常用的Linux vi命令,下面介绍的10个vi命令虽然很多不为人知,但是在实际应用中又能让你大大提高效率. ...

  9. Eclipse中用Logcat调试程序

    调试程序的一种方法是用Logcat程序,在Eclipse中windows->show view->other->android->logcat可打开. 然后程序加入androi ...

  10. using-ef-code-first-with-an-existing-database

    http://weblogs.asp.net/scottgu/using-ef-code-first-with-an-existing-database http://weblogs.asp.net/ ...