博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HTML5商城开发三 jquery 星星评分插件
阅读量:4353 次
发布时间:2019-06-07

本文共 2023 字,大约阅读时间需要 6 分钟。

展示:

 

实现方法:

1.html引用star-grade.js

    
    

2.css样式

@charset "utf-8";/* CSS Document */.starscore {    width: 200px;    height: 30px;}    .starscore i {        width: 14px;        height: 14px;        background: url(images/gray.gif) no-repeat; /* 14x14的灰色星星图标 */        display: inline-block;        vertical-align: middle;        background-size: contain;     }        .starscore i.inred, .starscore i.onred {            background: url(images/yel.gif) no-repeat; /* 14x14的黄色星星图标 */        }.starscore_lg > i {    width: 18px;    height: 18px;}.starscore_sm > i {    width: 12px;    height: 12px;}

3.插件js源码

/**   jq扩展--星星评分插件**   通过对象的属性data-score获取评分值*   星星使用元素i表示,绑定星星背景图*   鼠标进入、离开事件的绑定样式为inred,改变背景图*   点击事件的绑定样式为onred,改变背景图*/(function ($) {    "use strict";    $.fn.BindStars = function () {        var starElement = $(this);        starElement.children("i").mouseleave(function () { starElement.find("i").each(function (index) { $(this).removeClass("inred"); }); }); starElement.children("i").mouseenter(function () { var curIndex = starElement.find("i").index(this); starElement.find("i").each(function (index) { if (index <= curIndex) { $(this).addClass("inred"); } else { $(this).removeClass("inred"); } }); }); starElement.children("i").click(function () { var curIndex = starElement.find("i").index(this); starElement.find("i").each(function (index) { if (index <= curIndex) { $(this).addClass("onred"); } else { $(this).removeClass("onred"); } }); starElement.attr("data-score", curIndex + 1); }); }; $.fn.SetStars = function (score) { var scoreStr = ""; for (var i = 0; i < 5; i++) { if (i < score) { scoreStr += ""; } else { scoreStr += ""; } } $(this).html(scoreStr); }; })(window.jQuery);

 

转载于:https://www.cnblogs.com/xcsn/p/7779269.html

你可能感兴趣的文章
jvm架构以及Tomcat优化
查看>>
数据库の目录
查看>>
vmware安装rhel 7
查看>>
[复合材料] 编织复合材料单胞周期性边界条件编程问题
查看>>
Paxos协议笔记
查看>>
php之快速入门学习-15(php函数)
查看>>
【01背包问题】
查看>>
我所知道的数据库8-DML语言
查看>>
Python学习笔记——面向对象基础
查看>>
SQL Server 2012安装时如何不安装自带的Visual Studio
查看>>
网络传输协议总结(转载)
查看>>
C#.NET 大型企业信息化系统集成快速开发平台 4.2 版本 - 角色权限的配置页面改进优化...
查看>>
如何编写Spring-Boot自动配置
查看>>
(三)Asp.net web api中的坑-【http post请求中的参数】
查看>>
洛谷跑路
查看>>
使用DbProviderFactories.GetFactory方法需要配置数据库提供者
查看>>
Ubuntu || LinuxMint 配置apache虚拟主机
查看>>
HTML—链接
查看>>
将进程设置为守护进程
查看>>
用连接池提高Servlet访问数据库的效率
查看>>