This article mainly introduces the basic control methods for jQuery operations, and analyzes common techniques such as jQuery controls for style, ID acquisition, traversal, and attribute operations based on examples, for more information about jQuery's basic control operations, see the following example. We will share this with you for your reference. The details are as follows:
1. Obtain the control based on the style class of the control.
The Code is as follows:
$ (". ClassName") ...... // className indicates the control style.
2. Obtain the control based on its ID.
The Code is as follows:
$ ("# Id ")......
3. Obtain the control based on the control name
$("input[name='objName']")....../*$("check[name='objName']")......*/$("[name=objName]:checkbox")......$("select[name='objName']")......
4. traverse a group of controls
$ (". ClassName "). each (function () {$ (this ). attr ("title", "click to maintain"); // $ (this) Get the object Currently traversed}); for (var I = 0; I <$ (". className "). length; I ++) {$ (". className: eq ("+ I + ")"). attr ("title", "click to maintain ");}
5. Operation Control CSS style
$ ("# ObjId" ).css ("attribute name"); // obtain the CSS attributes of the current object, such as: $ ("# userName" ).css ("color "); returns the userName color $ ("# objId" ).css ("attribute name", "value"); // sets the CSS attribute for the current control, for example: $ ("# userName" ).css ("color", "# FFCCFF"); set the userName color to # FFCCFF
6. Common Properties of the Operation Control
$ ("Input [name = 'age']"). attr ("property name"); // get the basic property of the control $ ("input [name = 'age']"). attr ("attribute name", "value"); // you can specify the basic attributes of a widget, for example, $ ("# input [name = 'age']"). attr ("size", "30 ");
I hope this article will help you with jQuery programming.