Explanation of several symbols of jQuery

web front end eight thousand eight hundred and thirty-nine 13 years ago (2011-09-28)

Jquery selector

1. $。 In jQuery, the syntax of $("<span>") is equivalent to $(document. createElement ("span")). This is a usage. When selecting elements, it also uses the following: [attribute $=value]. Matching a given attribute is an element that ends with some value. Here is an example:
HTML code
<input name="newsletter" />
<input name="milkman" />
<input name="jobletter" />
JQuery code:
$("input[name$='letter']")
result:
[ <input name="newsletter" />, <input name="jobletter" /> ]
2. !。 Selector: [attribute!=value], matching all elements that do not contain the specified attribute or the attribute is not equal to the specific value. This selector is equivalent to: not ([attr=value]).
For example:
HTML code
<input type="checkbox" name="newsletter" value="Hot Fuzz" />
<input type="checkbox" name="newsletter" value="Cold Fusion" />
<input type="checkbox" name="accept" value="Evil Plans" />
JQuery code:
$("input[name!='newsletter']").attr("checked", true);
result:
[ <input type="checkbox" name="accept" value="Evil Plans" checked="true" /> ]
3. *。 Selector: [attribute *=value], the element that matches the given attribute to contain some values. Give an example:
HTML code:
<input name="man-news" />
<input name="milkman" />
<input name="letterman2" />
<input name="newmilk" />
JQuery code:
$("input[name*='man']")
result:
[ <input name="man-news" />, <input name="milkman" />, <input name="letterman2" /> ]
4. @。 Matches the element containing the given attribute. Note that in jQuery 1.3, the leading @ symbol has been abolished! If you want to be compatible with the latest version, simply remove the @ symbol

Yes.
5. ^。 Selector: [attribute ^=value]. Matching a given attribute is an element starting with some value. Here is an example to illustrate:
HTML code:
<input name="newsletter" />
<input name="milkman" />
<input name="newsboy" />
JQuery code:
$("input[name^='news']")
result:
[ <input name="newsletter" />, <input name="newsboy" /> ]

In jquery, when you use $("input [name='metaId ']"). val(), you cannot directly obtain the value of the selected radio, but only the first value of the radio tag. This may be related to the search of jquery using xpath language, but we usually want to obtain the value of the selected radio. There are several methods:

1. Use $("input [name='metaId ']: checked"). val() to obtain//name represents the name attribute name in radio

2. Use $(": radio: checked"). val() to get//limit the page to only one set of radio tags