jQuery Raty星級(jí)評(píng)分插件使用方法實(shí)例分析
本文實(shí)例講述了jQuery Raty星級(jí)評(píng)分插件使用方法。分享給大家供大家參考,具體如下:
使用jQuery Raty,可以很方便的在頁面上嵌入一個(gè)評(píng)分組件,如下所示:
使用方法很簡(jiǎn)單,首先從https://github.com/wbotelhos/raty下載raty的源代碼(依賴于jquery)
然后在頁面中引入相應(yīng)的js文件、css文件、圖片資源,在需要添加評(píng)分組件的元素上(比如span標(biāo)簽)添加下面的jquery代碼即可:
$('span').raty();
以上為jQuery Raty的缺省使用方法,此外,該組件還支持豐富的傳入?yún)?shù)和回調(diào)函數(shù),例如:
設(shè)置jQuery Raty的初始評(píng)分:
評(píng)分回調(diào)函數(shù)
如果需要根據(jù)后臺(tái)動(dòng)態(tài)設(shè)置初始評(píng)分,可以使用回調(diào)函數(shù)實(shí)現(xiàn)。例如使用div中的data-attribute屬性:
<div data-score="1"></div>
$('div').raty({ score: function() { return $(this).attr('data-score'); } });
還可以改變星星的個(gè)數(shù):
$('div').raty({ number: 10 });
只讀模式:
$('div').raty({ readOnly: true, score: 3 });
點(diǎn)擊事件:
$('div').raty({ click: function(score, evt) { alert('ID: ' + this.id + "\nscore: " + score + "\nevent: " + evt); } });
路徑:
變更圖標(biāo)保存的位置,所有圖標(biāo)需要位于同一目錄下,路徑結(jié)尾的/不添加也可以
<div data-path="assets/images"></div>
$('div').raty({ path: function() { return this.getAttribute('data-path'); } });
取消評(píng)分:
$('div').raty({ cancel: true });
全局改變?cè)O(shè)置:
你可以全局更改上述提到的所有設(shè)置 $.fn.raty.defaults.OPTION = VALUE;
. 該語句必須添加在插件綁定之前。
$.fn.raty.defaults.path = assets; $.fn.raty.defaults.cancel = true;
參數(shù)列表:
cancel : false // Creates a cancel button to cancel the rating. cancelClass : 'raty-cancel' // Name of cancel's class. cancelHint : 'Cancel this rating!' // The cancel's button hint. cancelOff : 'cancel-off.png' // Icon used on active cancel. cancelOn : 'cancel-on.png' // Icon used inactive cancel. cancelPlace : 'left' // Cancel's button position. click : undefined // Callback executed on rating click. half : false // Enables half star selection. halfShow : true // Enables half star display. hints : ['bad', 'poor', 'regular', 'good', 'gorgeous'] // Hints used on each star. iconRange : undefined // Object list with position and icon on and off to do a mixed icons. mouseout : undefined // Callback executed on mouseout. mouseover : undefined // Callback executed on mouseover. noRatedMsg : 'Not rated yet!' // Hint for no rated elements when it's readOnly. number : 5 // Number of stars that will be presented. numberMax : 20 // Max of star the option number can creates. path : undefined // A global locate where the icon will be looked. precision : false // Enables the selection of a precision score. readOnly : false // Turns the rating read-only. round : { down: .25, full: .6, up: .76 } // Included values attributes to do the score round math. score : undefined // Initial rating. scoreName : 'score' // Name of the hidden field that holds the score value. single : false // Enables just a single star selection. space : true // Puts space between the icons. starHalf : 'star-half.png' // The name of the half star image. starOff : 'star-off.png' // Name of the star image off. starOn : 'star-on.png' // Name of the star image on. target : undefined // Element selector where the score will be displayed. targetFormat: '{score}' // Template to interpolate the score in. targetKeep : false // If the last rating value will be keeped after mouseout. targetScore : undefined // Element selector where the score will be filled, instead of creating a new hidden field (scoreName option). targetText : '' // Default text setted on target. targetType : 'hint' // Option to choose if target will receive hint o 'score' type. starType : 'img' // Element used to represent a star.
回調(diào)函數(shù)列表:
$('div').raty('score'); // Get the current score. $('div').raty('score', number); // Set the score. $('div').raty('click', number); // Click on some star. $('div').raty('readOnly', boolean); // Change the read-only state. $('div').raty('cancel', boolean); // Cancel the rating. The last param force the click callback. $('div').raty('reload'); // Reload the rating with the current configuration. $('div').raty('set', { option: value }); // Reset the rating with new configurations. $('div').raty('destroy'); // Destroy the bind and give you the raw element. $('div').raty('move', number); // Move the mouse to the given score point position.
更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jQuery擴(kuò)展技巧總結(jié)》、《jQuery常用插件及用法總結(jié)》、《jQuery切換特效與技巧總結(jié)》、《jQuery遍歷算法與技巧總結(jié)》、《jQuery常見經(jīng)典特效匯總》、《jQuery動(dòng)畫與特效用法總結(jié)》及《jquery選擇器用法總結(jié)》
希望本文所述對(duì)大家jQuery程序設(shè)計(jì)有所幫助。
- jQuery Raty 一款不錯(cuò)的星級(jí)評(píng)分插件
- 如何實(shí)現(xiàn)星星評(píng)價(jià)(jquery.raty.js插件)
- 基于jQuery的星級(jí)評(píng)分插件
- jQuery滿意度星級(jí)評(píng)價(jià)插件特效代碼分享
- jquery插件star-rating.js實(shí)現(xiàn)星級(jí)評(píng)分特效
- jquery星級(jí)插件、支持頁面中多次使用
- jQuery插件-jRating評(píng)分插件源碼分析及使用方法
- jquery五角星評(píng)分插件示例分享
- jQuery超贊的評(píng)分插件(8款)
相關(guān)文章
jQuery實(shí)現(xiàn)數(shù)秒后自動(dòng)提交form的方法
這篇文章主要介紹了jQuery實(shí)現(xiàn)數(shù)秒后自動(dòng)提交form的方法,實(shí)例分析了jQuery實(shí)現(xiàn)form表單延時(shí)提交的技巧,需要的朋友可以參考下2015-03-03在JavaScript中重寫jQuery對(duì)象的方法實(shí)例教程
這篇文章主要介紹了在JavaScript中重寫jQuery對(duì)象的方法,在某些情況下jQuery無法滿足應(yīng)用開發(fā)的時(shí)候可以采用javascript重寫jQuery方法來滿足功能的實(shí)現(xiàn),需要的朋友可以參考下2014-08-08jquery插件jquery.nicescroll實(shí)現(xiàn)圖片無滾動(dòng)條左右拖拽的方法
這篇文章主要介紹了jquery插件jquery.nicescroll實(shí)現(xiàn)圖片無滾動(dòng)條左右拖拽的方法,實(shí)例分析了jquery.nicescroll插件實(shí)現(xiàn)圖片拖拽效果的方法,需要的朋友可以參考下2015-08-08通過上下左右鍵和回車鍵切換光標(biāo)實(shí)現(xiàn)代碼
客戶有這樣一個(gè)需求在列表中的文本框里輸入數(shù)據(jù)時(shí),要能夠通過上下左右鍵來切換光標(biāo),按回車鍵就把光標(biāo)移到下一個(gè)文本框,接下來將為你介紹下如何實(shí)現(xiàn),感興趣的朋友可以參考下2013-03-03jQuery實(shí)現(xiàn)的導(dǎo)航下拉菜單效果
這篇文章主要介紹了jQuery實(shí)現(xiàn)的導(dǎo)航下拉菜單效果,涉及jQuery響應(yīng)鼠標(biāo)事件動(dòng)態(tài)操作頁面元素的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2016-07-07在次封裝easyui-Dialog插件實(shí)現(xiàn)代碼
在次封裝easyui-Dialog插件實(shí)現(xiàn)代碼,需要的朋友可以參考下。2010-11-11Visual Studio中的jQuery智能提示設(shè)置方法
Visual Studio中的jQuery智能提示設(shè)置方法,喜歡用vs2008開發(fā)的朋友可以參考下。2010-03-03jquery實(shí)現(xiàn)點(diǎn)擊左右按鈕切換圖片
這篇文章主要為大家詳細(xì)介紹了jquery實(shí)現(xiàn)點(diǎn)擊左右按鈕切換圖片,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-01-01