JQ get form values and assignment codes
$ ("#keyword") [0].value = "";
/* Get the Text.areatext value * *
var textval = $ ("#text_id"). attr ("value");
Or
var textval = $ ("#text_id"). Val ();
/* Get the value of the radio button * *
var Valradio = $ ("input[type=radio]:checked"). Val ();
/* Get a set of radio items named (items) the value of the selected item * *
var item = $ (' input[name=items]:checked '). Val ();
/* Get check box value * *
var checkboxval = $ ("#checkbox_id"). attr ("value");
/* Get the value of the Drop-down list * *
var selectval = $ (' #select_id '). Val ();
/* text box, text area * *
$ ("#text_id"). attr ("value");/empty content
$ ("#text_id"). attr ("value", ' test ');//fill content
/* Multi-selection box checkbox*/
$ ("#chk_id"). attr ("checked");//Leave it unchecked
$ ("#chk_id"). attr ("Checked", true);//tick
if ($ ("#chk_id"). attr (' checked ') ==true)//judge whether it has been selected
/* Single select group radio*/
$ ("Input[type=radio]"). attr ("Checked", ' 2 ');//Set value=2 item as current selected
/* Dropdown box select*/
$ ("#select_id"). attr ("value", ' test ');//Set Value=test item is currently selected
$ ("Testtest2"). Appendto ("#select_id")//option to add a drop-down box
$ ("#select_id"). empty ();//Empty Drop-down box
/* Get a set of radio items named (items) the value of the selected item * *
var item = $ (' input[name=items]:checked '). Val (); Val () = undefined if it is not selected
/* Get the text of the Select selected item/*
var item = $ ("Select[name=items] option:selected"). Text ();
The second element of the/*select drop-down box is the current selected value.
$ (' #select_id ') [0].selectedindex = 1;
/*radio the second element of the radio group is the current selected value.
$ (' input[name=items] '). Get (1). checked = true;
/* Reset Form * *
$ ("form"). each (function () {
. Reset ();
});
jquery values and assigns HTML elements
jquery gives the base control a value, assignment Textbox:var str = $ (' #txt '). Val (); $ (' #txt '). Val ("Set Lbl Value"); text box, text area: $ ("#text_id"). attr ("Value", "");/empty contents $ ("#text_id"). attr ("value", ' test ');/fill Content
jquery gives the base control a value, an assignment
Textbox:
var str = $ (' #txt '). Val ();
$ (' #txt '). Val ("Set Lbl Value");
text box, text area:
$ ("#text_id"). attr ("Value", "");/empty content
$ ("#text_id"). attr ("value", ' test ');//fill content
Lable:
var str = $ (' #lbl '). Text ();
$ (' #lbl '). Text ("Set lbl Value");
var Valradio = $ ("input[@type =radio][@checked]"). Val ();
var item = $ (' input[@name =items][@checked] '). Val ();
var checkboxval = $ ("#checkbox_id"). attr ("value");
var selectval = $ (' #select_id '). Val ();
Multi-selection box checkbox:
$ ("#chk_id"). attr ("Checked", "");//Leave it unchecked
$ ("#chk_id"). attr ("Checked", true);//tick
if ($ ("#chk_id"). attr (' checked ') ==true)//judge whether it has been selected
Radio Group Radio:
$ ("input[@type =radio]"). attr ("Checked", ' 2 '); Set the value=2 item to the current selected item
Dropdown box Select:
$ ("#select_id"). attr ("value", ' test ');//Set Value=test item is currently selected
$ ("<option value= ' test ' >test</option><option value= ' test2 ' >test2</option>"). Appendto ("# select_id ")/option to add a dropdown box
$ ("#select_id"). empty ();//Empty Drop-down box
Gets the value of a set of radio selected items named (items)
var item = $ (' input[@name =items][@checked] '). Val ()//If not selected, val () = undefined
Gets the text of the Select selected item
var item = $ ("select[@name =items] option[@selected]"). Text ();
The second element of the Select Drop-down box is the currently selected value
$ (' #select_id ') [0].selectedindex = 1;
Radio the second element of a radio group is the currently selected value
$ (' input[@name =items] '). Get (1). checked = true;
Resetting a form
$ ("form"). each (function () {
. Reset ();
});
Summary: jquery gives the base control a value, assignment Textbox:var str = $ (' #txt '). Val (); $ (' #txt '). Val ("Set Lbl Value"); text box, text area: $ ("#text_id"). attr ("Value", "");/empty contents $ ("#text_id"). attr ("value", ' test ');/fill Content
jquery gives the base control a value, an assignment
Textbox:
var str = $ (' #txt '). Val ();
$ (' #txt '). Val ("Set Lbl Value");
text box, text area:
$ ("#text_id"). attr ("Value", "");/empty content
$ ("#text_id"). attr ("value", ' test ');//fill content
Lable:
var str = $ (' #lbl '). Text ();
$ (' #lbl '). Text ("Set lbl Value");
var Valradio = $ ("input[@type =radio][@checked]"). Val ();
var item = $ (' input[@name =items][@checked] '). Val ();
var checkboxval = $ ("#checkbox_id"). attr ("value");
var selectval = $ (' #select_id '). Val ();
Multi-selection box checkbox:
$ ("#chk_id"). attr ("Checked", "");//Leave it unchecked
$ ("#chk_id"). attr ("Checked", true);//tick
if ($ ("#chk_id"). attr (' checked ') ==true)//judge whether it has been selected
Radio Group Radio:
$ ("input[@type =radio]"). attr ("Checked", ' 2 '); Set the value=2 item to the current selected item
Dropdown box Select:
$ ("#select_id"). attr ("value", ' test ');//Set Value=test item is currently selected
$ ("<option value= ' test ' >test</option><option value= ' test2 ' >test2</option>"). Appendto ("# select_id ")/option to add a dropdown box
$ ("#select_id"). empty ();//Empty Drop-down box
Gets the value of a set of radio selected items named (items)
var item = $ (' input[@name =items][@checked] '). Val ()//If not selected, val () = undefined
Gets the text of the Select selected item
var item = $ ("select[@name =items] option[@selected]"). Text ();
The second element of the Select Drop-down box is the currently selected value
$ (' #select_id ') [0].selectedindex = 1;
Radio the second element of a radio group is the currently selected value
$ (' input[@name =items] '). Get (1). checked = true;
Resetting a form
$ ("form"). each (function () {
. Reset ();
});
has a qualified child node selector: $ ("mix1[mix2]"): Returns the MIX1 node containing the mix2. such as: $ ("Div[a]"): Div containing a label.
This is not the same as $ ("div a"). The latter represents a tag in the Div, and returns a Label object, which returns a DIV tag object.
Colon-Qualified node selector: $ ("Mix:condition"): Mix label, and meet qualifying criteria.
E:root: Type E, and is the root element of the document
E:nth-child (N): is a child element of the nth type E of its parent element, starting with a base of 1
E:first-child: Is the 1th child element of its parent element of type E
E:last-child: Is the child element of the last type E of its parent element
E:only-child: And is the only child element of its parent element of type E
E:empty: element of type E with no child element (including text node)
E:enabled
e:disabled: User interface elements of type E, allowed or prohibited
e:checked: Type E, user interface element in a selected state (such as a radio button or check box)
E:visible: Select all visible elements (display value is block or visible,visibility value is visible element, excluding hide field)
E:hidden: Select all hidden elements (not hide fields, and display values are blocks or visible,visibility values are visible elements)
E:not (s): Type E, mismatched selector s
E:eq (n), E:GT (n), E:lt (n): element-Qualified
E:first: Equivalent to E:eq (0)
E:last: Last matching element
E:even: An element with an even number ordinal from a matching element set
E:odd: An odd number of elements from a matching set of elements
E:parent: Select all elements that contain child elements (including the text node)
E:contains (' Test '): Selects all elements that contain the specified text
Form selector:
E:input: Select Form Element (Input,select,textarea,button)
E:text: Select all text fields (type= "text")
E:password: Select all password fields (type= "password")
E:radio: Select all radio buttons (type= "Radio")
E:checkbox: Select all check boxes (type= "checkbox")
E:submit: Select all Submit Buttons (type= "Submit")
E:image: Select all image Fields (type= "image")
E:reset: Select all cleared fields (type= "reset")
E:button: Select All buttons (type= "button")
Including E:hidden, of course.
8.xPath Path Query:
Let's introduce the syntax of XPath:
/: Select root node
: Select all eligible nodes in the document, regardless of where the node is located
.: Select the current node
..: Select the parent node of a single front node
@: Select attributes, which have been mentioned before (property selector)
NodeName: Select all nodes under the node
The application in jquery:
The root node is rarely used, and is commonly used as the following example:
$ ("div/p") equals $ ("div>p")
$ ("div//p") equals $ ("div p")
$ ("//div/.") /P "): P tag under the parent node of all DIV nodes
There is also a relative path to the writing and support of the axis selector, is not applied, do not introduce ... It's a whole lot.
Other uses of $:
$ (HTML node): Dynamically creates a DOM element wrapped by a jquery object, based on the supplied raw HTML tag string.
$ ("Hello"). Appendto ("#body");//Add Hello to the BODY element
$ (document): Web Document Object
$ (document.body): Page body object, and $ ("body") is the same
$ (function) executes this function:D om is loaded. So $ (document). Ready () can write $ ()
$ (Selector section, selector source): This example illustrates
$ ("Input:radio", Document.forms[0]): In the first form of the document, search for all radio buttons
$ ("div", xml.responsexml): Querying all DIV elements in the specified XML document
The selector source can be: A DOM element for the context, a document, or a jquery object
There are two more: $.extend (prop) and $.noconflict () are compatible with Plug-ins and other libraries, and write later
Dropdown box, radio box, multi-selection box finishing
1, dropdown box:
var cc1 = $ (". FORMC select[@name = ' country '] option[@selected]"). Text (); Gets the text of the selected item in the Drop-down menu (note that there are spaces in the middle)
var CC2 = $ ('. FORMC select[@name = ' country '] '). Val (); Gets the value of the selected item in the Drop-down menu
var cc3 = $ ('. FORMC select[@name = ' country '] '). attr ("id"); Gets the id attribute value of the selected item in the Drop-down menu
$ ("#select"). Empty ()//Empty Drop-down box//$ ("#select"). HTML (");
$ ("1111"). Appendto ("#select")//option to add a drop-down box
A little explanation:
1.select[@name = ' country '] option[@selected] Represents the Name property,
and the attribute value is the option element with the selected attribute inside the Select element of ' country ';
It can be seen that a @ begins with a property that follows.
2, Radio Box:
$ ("input[@type =radio][@checked]"). Val (); Gets the value of the selected item in the Radio box (note that there are no spaces in the middle)
$ ("input[@type =radio][@value =2]"). attr ("Checked", ' checked '); Sets the value=2 of the radio box to the selected state. (Note that there are no spaces in between)
3, check box:
$ ("input[@type =checkbox][@checked]"). Val (); Gets the value of the first item selected in the check box
$ ("input[@type =checkbox][@checked]"). each (function () {//, because the check box is typically selected for more than one, you can cycle the output
Alert ($ (this). Val ());
});
$ ("#chk1"). attr ("Checked", "");/no tick.
$ ("#chk2"). attr ("Checked", true);/tick
if ($ ("#chk1"). attr (' checked ') ==undefined) {}//judge whether it has been ticked
Suppose there is a button in a form id= "save"
$ (document). Ready (function () {
$ ("#save"). Click (function () {
$ ("#save"). attr ("Disabled", true);//set to not available
$ ("#form1") [0].submit ();//If you have many Form1 forms, it doesn't matter, only the first one will submit haha.
});
});
Remove the text of the selected item from the Pull menu;
Gets and sets the value of the Drop-down menu;
Empty the Drop-down menu;
Add elements to the following menu;
Take a single marquee value;
Selection of radio or check buttons;
Take the check box value;
Determines whether a single selection or check box is selected;
element is not available;
The decision element is not available.
1. Remove the text of the selected item from the Pull menu
$ ("#select option[selected]"). Text ();//select and option have spaces, option is child element of select
$ ("#select option:selected"). Text ()//if written as $ ("#select"). Text () Select all Drop-down menu texts
2. Get and set the value of the Drop-down menu
$ ("#select"). Val ();//Fetch value
$ ("#select"). Val ("value");/setting, if there is an option in the select that has value, the option is selected, and if it does not exist, the select does not make any changes
3. Empty the Pull-down menu
$ ("#select"). empty ();
$ ("#select"). HTML ("");
4. Add elements to the following menu
$ (' <option value= "1" >1</option> "). Appendto ($ (" #select "));
$ ("#select"). Append (' <option value= ' 1 ">1</option> ');
5. Take a single marquee value
$ ("#id [checked]"). Val ();
6. Choice of radio or check button
$ ("#id [Value=val]"). attr ("Checked", true);/select
$ ("#id [Value=val]"). attr ("Checked", "");/Cancel Selection
$ ("#id [Value=val]"). attr ("checked", false);/Cancel Selection
$ ("#id [Value=val]"). Removeattr ("checked");/Cancel Selection
7. Take check box value
$ ("input[type=checkbox][checked]"). each (function () {
Alert ($ (this). Val ());
})
If you use $ ("input[type=checkbox][checked]"). Val (), only the first selected value is returned
8. Determine if a single selection or check box is selected
if ($ ("#id"). attr ("checked")) {}//judgment selected
if ($ ("#id"). attr ("checked") ==true) {}//judgment selected
if ($ ("#id"). attr ("checked") ==undefined) {}//judgment not selected
9. Elements available are not available
$ ("#id"). attr ("disabled", false);//set to Available
$ ("#id"). attr ("Disabled", true);//set to not available
10. Determine that elements are not available
if ($ ("#id"). attr ("Disabled")) {}//judgment not available
if ($ ("#id"). attr ("disabled") ==undefined) {}//judgment available
Text Box action
Value: var textval = $ ("#text_id"). attr ("value");
var textval = $ ("#text_id"). Val ();
Clear content: $ ("#txt"). attr ("value", ");
Padding content: $ ("#txt"). attr ("value", ' 123′ ');
Text Field Operations
Value: var textval = $ ("#text_id"). attr ("value");
var textval = $ ("#text_id"). Val ();
Clear content: $ ("#txt"). attr ("value", ");
Padding content: $ ("#txt"). attr ("value", ' 123′ ');
radio button action
Value: var Valradio = $ ("input[@type =radio][@checked]"). Val (); Only one set of radio cases
var valradio =$ (' input[@name =chart][@checked] '). Val (); In multiple sets of radio cases, a set of values based on name
Dropdown box Action
Value: var selectval = $ (' #sell '). Val ();
Set Check: $ ("#select_id"). attr ("value", ' test ');//Set Value=test item as current selected
Add New Item: $ ("<option value= ' test ' >test</option><option value= ' test2 ' >test2</option>"). Appendto ("#select_id")//option to add a drop-down box
Empty drop-down Box: $ ("#select_id"). Empty ()//Empty dropdown box
Multi-selection box operation
Value: $ ("#chk_id"). attr ("Checked", "")//Unchecked value
$ ("#chk_id"). attr ("Checked", true);//Selected value
if ($ ("#chk_id"). attr (' checked ') ==undefined)//judge whether it has been selected