Juery usage notes (updating)

Source: Internet
Author: User

<Select id = "Select1" name = "D1">
<Option selected = "selected" value = "1"> 1 </option>
<Option value = "Guangdong"> 2 </option>
<Option value = "3"> 3 </option>
</Select>

1.doc ument. getElementById ("Select1 "). options. length = 0, juery implementation: $ ("# Select1 "). attr ("length", 0); $ ("# Select1 "). empty ();

2. var value = $ ("# Select1"). val (); value

3. $ ("# Select1"). append ("<option value = 'value'> text </option>"); add data

4. $ ("# Select1 option [value = Fujian]"). attr ("selected", "selected"); set or use

$ ("# Select1 option"). each (function (){
If ($ (this). val () = 'fujian '){
$ (This). attr ("selected", true );
}
});

5. $ ("# Select1") [0]. options. add (new Option ('text', 'value'); [0] This format can be returned to the native DOM.

Or $ ("# Select1"). get (0). options. add (new Option ('text', 'value '));

 

 

6. var keys = [];
Var values = [];

$ ("# LbHas option"). each (function (){
Keys. push ($ (this). attr ("value "));
Values.push({(this}.html ());
});

For (var I = 0; I <keys. length; I ++ ){
$ ("# LbAll option [value =" + keys [I] + "]"). remove ();
}

7.

If ($ ("# _ SupplyType option [selected = selected]" ).html () = "") // unavailable, the selected attribute is selected in IE8, the selected attribute is not available in IE6 and other browsers.
If (document. getElementById ("_ SupplyType"). options [document. getElementById ("_ SupplyType"). selectedIndex]. text = "") // feasible
If ($ ("# _ SupplyType option: selected" ).html () = "") // feasible
 

8.

How does jquery exit the each loop?

  Return false in the callback function. This applies to most jq methods. 
==================================================== 'False' will be returned stop a loop (like using 'Break' in a normal loop ').
Return 'true' to jump to the next loop (just like using 'contine' in a normal loop ').

 

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.