• js五星评分。


    先弄两张图片,

    然后写个div把图片放到里面,

    <div class="div-xx" style="z-index: 99;">
                        <span>如果喜欢的话可以评分诺!</span>
                        <button type="button" id="btn1" class="btn btn-primary"
                        ">提交评分</button>
    
                        <div style="background-image:url(../img/stark2.png); 27px;height:21px;float:left"
                             onmouseover="xx(1)" onmouseout="yc(0)" onclick="dj()" id="aa"></div>
                        <div style="background-image:url(../img/stark2.png); 27px;height:21px;float:left"
                             onmouseover="xx(2)" onmouseout="yc(1)" onclick="dj()" id="bb"></div>
                        <div style="background-image:url(../img/stark2.png); 27px;height:21px;float:left"
                             onmouseover="xx(3)" onmouseout="yc(2)" onclick="dj()" id="cc"></div>
                        <div style="background-image:url(../img/stark2.png); 27px;height:21px;float:left"
                             onmouseover="xx(4)" onmouseout="yc(3)" onclick="dj()" id="dd"></div>
                        <div style="background-image:url(../img/stark2.png); 27px;height:21px;float:left"
                             onmouseover="xx(5)" onmouseout="yc(4)" onclick="dj()" id="ee"></div>
                    </div>

    给每个图片加点击事件,然后写js代码

    var count = 0;
        function xx(n) {
            if (n == 1) {
                document.getElementById("aa").style.backgroundImage = "url(../img/stars2.png)";
                count = n;
    
            }
            else if (n == 2) {
                document.getElementById("aa").style.backgroundImage = "url(../img/stars2.png)";
                document.getElementById("bb").style.backgroundImage = "url(../img/stars2.png)";
                count = n;
    
            }
            else if (n == 3) {
    
                document.getElementById("aa").style.backgroundImage = "url(../img/stars2.png)";
                document.getElementById("bb").style.backgroundImage = "url(../img/stars2.png)";
    
                document.getElementById("cc").style.backgroundImage = "url(../img/stars2.png)";
                count = n;
    
            }
            else if (n == 4) {
                document.getElementById("aa").style.backgroundImage = "url(../img/stars2.png)";
                document.getElementById("bb").style.backgroundImage = "url(../img/stars2.png)";
                document.getElementById("cc").style.backgroundImage = "url(../img/stars2.png)";
                document.getElementById("dd").style.backgroundImage = "url(../img/stars2.png)";
                count = n;
            }
            else if (n == 5) {
                document.getElementById("aa").style.backgroundImage = "url(../img/stars2.png)";
                document.getElementById("bb").style.backgroundImage = "url(../img/stars2.png)";
                document.getElementById("cc").style.backgroundImage = "url(../img/stars2.png)";
                document.getElementById("dd").style.backgroundImage = "url(../img/stars2.png)";
                document.getElementById("ee").style.backgroundImage = "url(../img/stars2.png)";
                count = n;
            }
    
        }
        function yc(n) {
            if (n == 0) {
                document.getElementById("aa").style.backgroundImage = "url(../img/stark2.png)";
                count = 0;
            }
            else if (n == 1) {
                document.getElementById("aa").style.backgroundImage = "url(../img/stark2.png)";
                document.getElementById("bb").style.backgroundImage = "url(../img/stark2.png)";
                count = 0;
            }
            else if (n == 2) {
                document.getElementById("aa").style.backgroundImage = "url(../img/stark2.png)";
                document.getElementById("bb").style.backgroundImage = "url(../img/stark2.png)";
                document.getElementById("cc").style.backgroundImage = "url(../img/stark2.png)";
                count = 0;
            }
            else if (n == 3) {
                document.getElementById("aa").style.backgroundImage = "url(../img/stark2.png)";
                document.getElementById("bb").style.backgroundImage = "url(../img/stark2.png)";
                document.getElementById("cc").style.backgroundImage = "url(../img/stark2.png)";
                document.getElementById("dd").style.backgroundImage = "url(../img/stark2.png)";
                count = 0;
            }
            else if (n == 4) {
                document.getElementById("aa").style.backgroundImage = "url(../img/stark2.png)";
                document.getElementById("bb").style.backgroundImage = "url(../img/stark2.png)";
                document.getElementById("cc").style.backgroundImage = "url(../img/stark2.png)";
                document.getElementById("dd").style.backgroundImage = "url(../img/stark2.png)";
                document.getElementById("ee").style.backgroundImage = "url(../img/stark2.png)";
                count = 0;
            }
        }
        function dj() {
            document.getElementById("aa").onmouseover = null;
            document.getElementById("bb").onmouseover = null;
            document.getElementById("cc").onmouseover = null;
            document.getElementById("dd").onmouseover = null;
            document.getElementById("ee").onmouseover = null;
    
            document.getElementById("aa").onmouseout = null;
            document.getElementById("bb").onmouseout = null;
            document.getElementById("cc").onmouseout = null;
            document.getElementById("dd").onmouseout = null;
            document.getElementById("ee").onmouseout = null;
        }

    写完可以取n的值来加入数据库了。

  • 相关阅读:
    WebService通过SOAP头进行身份验证
    【笔记】NIOS II spi详解
    【笔记】关于NIOS II PIO的几个问题
    【笔记】NIOS II Interval Timer Core详解
    【原创】基于NIOS II SPI的ads8321驱动
    【笔记】MATLAB一些常用函数
    【原创】解决on_chip_memory过小的问题,解决Unable to reach errno ...的问题
    【原创】基于FPGA的等精度测频方法(学习实验)
    【原创】等效采样状态机控制工程(测试通过,待完善说明书)
    【原创】基于NIOS II的ADS1256 SPI驱动
  • 原文地址:https://www.cnblogs.com/junmoli/p/6760370.html
Copyright © 2020-2023  润新知