Js star rating _ javascript skills

Source: Internet
Author: User
Here, I would like to share with my friends the effect of using js to score stars in the mall. I hope to help you with the following html:

Css style:

.starts,.starts ul{float:left;}.starts{padding-left:16px;padding-top:7px;}.starts ul li{width:32px;height:31px;float:left;background:#ddd;padding-right:3px;}.starts ul li.on{background:red;}.starts ul span{display:inline;float:left;padding-left:10px;height:31px;line-height:31px;}

The js call is as follows:

Window. onload = function () {var s = document. getElementById ("pingStar"), m = document. getElementById ('dir'), n = s. getElementsByTagName ("li"), input = document. getElementById ('startp '); // Save the selected value clearAll = function () {for (var I = 0; I <n. length; I ++) {n [I]. className = ''; }}for (var I = 0; I <n. length; I ++) {n [I]. onclick = function () {var q = this. getAttribute ("rel"); clearAll (); input. value = q; for (var I = 0; I <q; I ++) {n [I]. className = 'on';} m. innerHTML = this. getAttribute ("title");} n [I]. onmouseover = function () {var q = this. getAttribute ("rel"); clearAll (); for (var I = 0; I <q; I ++) {n [I]. className = 'on';} n [I]. onmouseout = function () {clearAll (); for (var I = 0; I <input. value; I ++) {n [I]. className = 'on ';}}}}

View demo http://demo.jb51.net/js/2014/jsxxdf/

If you like to use jquery-based star scoring effect, you can refer to this address: http://www.jb51.net/jiaoben/195077.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.