How js achieves star scoring

Source: Internet
Author: User

How js achieves star scoring

Many websites have such a star scoring effect. Today, we will look at how js can be used to achieve the scoring effect.

Detailed results
1. When the mouse moves up, the stars light up and the text below is displayed. When the mouse moves out, the stars are gray and the text below is not displayed.
2. Move the mouse over a star, and all the stars before it will be bright.
3. move the cursor over a star and click it. The score is displayed.

The Code is as follows:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

<! Doctype html>

<Html>

<Head>

<Meta charset = "gbk">

<Title> switch </title>

<Style>

. Wrapper {width: 300px; margin: 10px auto; font: 14px/1.5 arial ;}

/* Tab */

# Star {overflow: hidden ;}

# Star li {

Float: left;

Width: 20px;

Height: 20px;

Margin: 2px;

Display: inline;

Color: #999;

Font: bold 18px arial;

Cursor: pointer

}

# Star. act {

Color: # c00

}

# Star_word {

Width: 80px;

Height: 30px;

Line-height: 30px;

Border: 1px solid # ccc;

Margin: 10px;

Text-align: center;

Display: none

}

</Style>

<Script>

Window. onload = function (){

Var star = document. getElementById ("star ");

Var star_li = star. getElementsByTagName ("li ");

Var star_word = document. getElementById ("star_word ");

Var result = document. getElementById ("result ");

Var I = 0;

Var j = 0;

Var len = star_li.length;

Var word = ['bad', 'bad', 'two', "good", "good"]

For (I = 0; I <len; I ++ ){

Star_li [I]. index = I;

Star_li [I]. onmouseover = function (){

Star_word.style.display = "block ";

Star_word.innerHTML = word [this. index];

For (I = 0; I <= this. index; I ++ ){

Star_li [I]. className = "act ";

}

}

Star_li [I]. onmouseout = function (){

Star_word.style.display = "none ";

For (I = 0; I <len; I ++ ){

Star_li [I]. className = "";

}

}

Star_li [I]. onclick = function (){

Result. innerHTML = (this. index + 1) + "points ";

}

}

}

</Script>

</Head>

<Body>

<Div class = "wrapper">

Score result

<Span id = "result"> </span>

<Ul id = "star">

<Li>★</Li>

<Li>★</Li>

<Li>★</Li>

<Li>★</Li>

<Li>★</Li>

</Ul>

<Div id = "star_word"> General </div>

</Div>

</Body>

</Html>

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.