亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術文章
文章詳情頁

javascript實現評分功能

瀏覽:39日期:2023-06-19 18:36:01

本文實例為大家分享了js實現評分功能的具體代碼,供大家參考,具體內容如下

實現的效果如下:

javascript實現評分功能

具體代碼如下:

html部分:

<!DOCTYPE html><html lang='en'><head> <meta charset='UTF-8'> <meta name='viewport' content='width=device-width, initial-scale=1.0'> <meta http-equiv='X-UA-Compatible' content='ie=edge'> <link rel='stylesheet' href='http://www.aoyou183.cn/bcjs/index.css' > <title>評分</title></head><body> <div id='starRating'> <p class='photo'> <span><i class='high'></i><i class='nohigh'></i></span> <span><i class='high'></i><i class='nohigh'></i></span> <span><i class='high'></i><i class='nohigh'></i></span> <span><i class='high'></i><i class='nohigh'></i></span> <span><i class='high'></i><i class='nohigh'></i></span> </p> <p class='starNum'>0.0分</p> <div class='bottoms'> <a class='garyBtn cancleStar'>取消評分</a><a class='blueBtn sureStar'>確認</a> </div> </div> <script src='http://www.aoyou183.cn/bcjs/jquery.js'></script> <script src='http://www.aoyou183.cn/bcjs/index.js'></script></body></html>

CSS部分:

#starRating .photo span{ position: relative; display: inline-block; width: 44px; height: 42px; overflow: hidden; margin-right: 23px; cursor: pointer; /* border: 1px solid black; */}#starRating .photo span:last-child{ margin-right: 0px;}#starRating .photo span .nohigh{ position: absolute; width: 44px; height: 42px; top: 0; left: 0; background: url(./star.png);}#starRating .photo span .high { position: absolute; width: 44px; height: 42px; top: 0; left: 0; background: url(./star1.png);}#starRating .starNum { font-size: 26px; color: #de4414; margin-top: 4px; margin-bottom: 10px;}#starRating .photo{ margin-top: 30px;}#starRating .bottoms a { margin-bottom: 0;}#starRating .bottoms .garyBtn { margin-right: 57px!important;}#starRating .bottoms a { width: 130px; height: 35px; line-height: 35px; border-radius: 3px; display: inline-block; font-size: 16px; transition: all 0.2s linear; margin: 16px 0 22px; text-align: center; cursor: pointer;}.garyBtn { margin-right: 60px!important; background-color: #e1e1e1; color: #999999;}.blueBtn { background-color: #1968b1; color: #fff;}.blueBtn:hover { background: #0e73d0;}

index.js

$(function () { //評分 var starRating = 0; //鼠標移入 $(’.photo span’).on(’mouseenter’, function () { var index = $(this).index() + 1; $(this).prevAll().find(’.high’).css(’z-index’, 1); $(this).find(’.high’).css(’z-index’, 1); $(this).nextAll().find(’.high’).css(’z-index’, 0); $(’.starNum’).html((index * 2).toFixed(1) + ’分’); }); //鼠標離開 $(’.photo’).on(’mouseleave’, function () { $(this).find(’.high’).css(’z-index’, 0); var count = starRating / 2; console.log(count); if (count == 5) { $(’.photo span’).find(’.high’).css(’z-index’, 1); } else { $(’.photo span’).eq(count).prevAll().find(’.high’).css(’z-index’, 1); } $(’.starNum’).html(starRating.toFixed(1) + ’分’) }), //點擊 $(’.photo span’).on(’click’, function () { var index = $(this).index() + 1; $(this).prevAll().find(’.high’).css(’z-index’, 1) $(this).find(’.high’).css(’z-index’, 1); starRating = index * 2; $(’.starNum’).html(starRating.toFixed(1) + ’分’); //alert(’評分:’ + (starRating.toFixed(1) + ’分’)) }); //取消評分 $(’.cancleStar’).on(’click’,function () { starRating = 0; $(’.photo span’).find(’.high’).css(’z-index’,0); $(’.starNum’).html(starRating.toFixed(1)+’分’); }); //確定評分 $(’.sureStar’).on(’click’,function () { if(starRating===0) { alert(’最低一顆星!’); } else { alert(’評分:’+(starRating.toFixed(1)+’分’)) } })})

圖片stat.png和stat1.png分別如下

javascript實現評分功能

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: JavaScript
相關文章:
主站蜘蛛池模板: 国内精品久久久久影院薰衣草 | 亚洲欧美在线观看91偷拍 | 91原创视频 | 成人在线视频网址 | 91精品久久久久亚洲国产 | 国产偷自拍视频 | 黑人好太好长爱不了 | 欧美日韩国产综合视频一区二区三区 | 亚洲第一视频在线 | 免费一级毛片不卡不收费 | 国产精品吹潮在线播放 | 久久精品亚洲精品一区 | 久久成人精品免费播放 | 日韩色视 | 一级黄色生活片 | 日韩精品特黄毛片免费看 | 伊人狠狠丁香婷婷综合色 | 国内精自视频品线六区免费 | 一级黄色大片免费看 | 在线观看亚洲精品专区 | 日韩欧美黄色 | 国内精品不卡一区二区三区 | 久久影院中文字幕 | 轻轻操在线播放 | 337q日本大胆欧美人术艺术 | 美女被免费网站在线视频九色 | www免费播放观看在线视频 | 欧美草逼片 | 国产精品美女福利视频一区 | 欧美激情一区二区 | 国产成人一区二区三区视频免费蜜 | 欧美亚洲中日韩中文字幕在线 | 日韩 国产 欧美 精品 在线 | 一 级 黄 色生活片 一 级 黄 色蝶 片 | 99热这里都是国产精品 | 久久三级网站 | 欧美黑人与白人做爰 | 妞干网在线免费视频 | 久青草久青草高清在线播放 | 色天天天综合色天天碰 | 久久www免费人成_看片美女图 |