Click jQuery implementation button

Source: Internet
Author: User

Click jQuery implementation button

This article mainly introduces information about jQuery's button selection, and check box text box form verification. For more information, see

Click "select all"/"select multiple"/"check box" in jQuery to verify the form.

?

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

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

<! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN">

<Html>

<Head>

<Base href = "<% = basePath %>">

 

<Title> My JSP 'index. jsp 'starting page </title>

<Meta http-equiv = "pragma" content = "no-cache">

<Meta http-equiv = "cache-control" content = "no-cache">

<Meta http-equiv = "expires" content = "0">

<Meta http-equiv = "keywords" content = "keyword1, keyword2, keyword3">

<Meta http-equiv = "description" content = "This is my page">

<! --

<Link rel = "stylesheet" type = "text/css" href = "styles.css">

-->

<Script type = "text/javascript" src = "jquery-1.4.js"> </script>

<Script type = "text/javascript">

$ (Document). ready (function (){

// Button

$ ("# But"). click (function (){

Alert ("This is my JSP page ");

});

 

// Text box

$ ("# Btext"). click (function (){

Alert ($ ("# te"). val ());

});

 

// Drop-down list

$ ("# Sel"). change (function (){

Alert ($ ("# sel"). val ());

});

 

// Single region

$ ("# Uradio1"). click (function (){

Alert ($ ('input [name = "radiobuttid = on"]: checked'). val ());

});

$ ("# Uradio2"). click (function (){

Alert ($ ('input [name = "radiobutton"]: checked'). val ());

});

$ ("# Uradio3"). click (function (){

Alert ($ ('input [name = "radiobutton"]: checked'). val ());

});

 

// Check box

$ ("# Ucheck"). click (function (){

Var str = ""; // defines an array

$ ('Input [name = "checkbox"]: checked'). each (function () {// traverse each check box named interest, where the selected execution function

Str + = $ (this). val (); // Add the selected value to the array chk_value

 

});

Alert (str );

});

// Select all

$ ("# Checkall"). click (function (){

$ ("Input [name = 'items ']"). attr ("checked", true );

});

 

// None

$ ("# CheckallNo"). click (function (){

$ ("Input [name = 'items ']"). attr ("checked", false );

});

 

// Invert Selection

$ ("# Check_revsern"). click (function (){

$ ("Input [name = 'items ']"). each (function (){

$ (This). attr ("checked ",! $ (This). attr ("checked "));

});

});

 

// Select all/reselect

$ ("# CheckItems"). click (function (){

$ ("Input [name = 'items ']"). attr ("checked", $ (this). get (0). checked );

});

 

// Form Verification

$ ("# Nameid"). hide ();

$ ("# Ageid"). hide ();

 

$ ("# Ubu"). click (function (){

If ($ ("# name"). val () = ""){

$ ("# Nameid"). show ();

$ ("# Nameid"). fadeOut (3000 );

Return false;

} Else if ($ ("# age"). val () = ""){

$ ("# Ageid"). show ();

$ ("# Ageid"). fadeOut (3000 );

Return false;

}

Alert ($ ("# sel"). val ());

Alert ("name:" + $ ("# name"). val () + "" + "age" + $ ("# age"). val ());

});

 

});

</Script>

</Head>

 

<Body>

<! -- Button -->

<Input type = "button" value = "OK" id = "but"/> <br>

 

<! -- Text box -->

<Input type = "text" name = "text" id = "te"/> <input type = "button" id = "btext" value = "value"> <br>

 

<! -- Drop-down box -->

<Select id = "sel">

<Option value = "1"> 1 </option>

<Option value = "2"> 2 </option>

<Option value = "3"> 3 </option>

</Select>

<Br>

 

<! -- Single region -->

<Input type = "radio" name = "radiobutton" id = "uradio1" value = "1"> 1

<Input type = "radio" name = "radiobutton" id = "uradio2" value = "2"> 2

<Input type = "radio" name = "radiobutton" id = "uradio3" value = "3"> 3

<Br>

 

<! -- Check box -->

<Input type = "checkbox" name = "checkbox" value = "1"> 1

<Input type = "checkbox" name = "checkbox" value = "2"> 2

<Input type = "checkbox" name = "checkbox" value = "3"> 3

<Input type = "checkbox" name = "checkbox" value = "4"> 4

<Input type = "button" id = "ucheck" value = "OK">

<Br>

 

<! -- Select all and invert check boxes -->

<Input type = "checkbox" name = "checkItems" id = "checkItems" value = "select all/select none"/> select all/select none

<Br>

<Input type = "checkbox" name = "items" value = ""/> football

<Input type = "checkbox" name = "items" value = "basketball"/> basketball

<Input type = "checkbox" name = "items" value = "swimming"/> swimming

<Input type = "checkbox" name = "items" value = "singing"/> singing

<Br>

<Input type = "button" name = "checkall" id = "checkall" value = "select all"/>

<Input type = "button" name = "checkall" id = "checkallNo" value = "NONE"/>

<Input type = "button" name = "checkall" id = "check_revsern" value = ""/>

 

<! -- Form verification -->

<Form action = "">

Name: <input type = "text" id = "name"> <span id = "nameid" style = "color: # f00;"> name cannot be blank! </Span> <br>

Age: <input type = "text" id = "age"/> <span id = "ageid" style = "color: # f00;"> age cannot be blank! </Span> <br>

<Input type = "button" id = "ubu" value = "OK"/>

</Form>

</Body>

</Html>

 

The first release of cainiao. If any, I 'd like to point out

The above is all the content of this article. I hope you will like it.

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.