Jquery operation select

Source: Internet
Author: User

1. determine whether the select option contains Item $ ("# selectid option [@ Value = 'paravalue ']") of value = "paraValue". length> 02. add an Item $ ("# selectid") to the select option "). append ("<option value =''> 1111 <option> "); 3. delete an Item $ ("# selectid") from the select option "). remove ("<option value =''> 1111 <option> "); 4. in the select option, set the text of value = "paraValue" to "paraText" $ ("# selectid option: selected "). attr ("value", "paraValue "). attr ("text", "paraText"); 5. set the first Item of text = "paraText" in the select statement to $ ("# selectid option [@ text = 'paratext ']"). attr ("selected", "true") 6. set the Item of value = "paraValue" in select to $ ("# selectid option [@ value = 'paravalue ']"). attr ("selected", "true") 7. set the first Item in select to select $ ("# selectid option "). eq (0 ). attr ('selected', 'true'); 8. obtain the value $ ("# selectid") of the selected item "). val (); 9. get the text $ ("# selectid") of the selected item "). text (); 10. obtain the Index document of the selected item in the select statement. getElementById ("select1 "). selectedIndex; $ ("# selectid "). get (0 ). selectedIndex11. clear select items $ ("# selectid "). empty (); JS version: // 1. determine whether the select option contains the Item function jsSelectIsExitItem (objSelect, objItemValue) {var isExit = false; for (var I = 0; I; I ++) of Value = "paraValue) {if (objSelect. options [I]. value = objItemValue) {isExit = true; break;} return isExit;} // 2. add an Item function jsAddItemToSelect (objSelect, objItemText, objItemValue, objItemPos) to the select option {// determine if (jsSelectIsExitItem (objSelect, objItemValue )) {alert ("the Value of this Item already exists");} else {var varItem = new Option (objItemText, objItemValue); // objSelect. options [objSelect. options. length] = varItem; objSelect. options. add (varItem, objItemPos); alert ("successfully added") ;}}// 3. delete an Item function jsRemoveItemFromSelect (objSelect, objItemValue) from the select option {// determine whether if (jsSelectIsExitItem (objSelect, objItemValue) {for (var I = 0; I; I ++) {if (objSelect. options [I]. value = objItemValue) {objSelect. options. remove (I); break ;}} alert ("deleted successfully") ;}else {alert ("this select does not exist") ;}} // 4. modify the text of value = "paraValue" in the select option to "paraText" function jsUpdateItemToSelect (objSelect, objItemText, objItemValue) {// determine if (jsSelectIsExitItem (objSelect, objItemValue )) {for (var I = 0; I; I ++) {if (objSelect. options [I]. value = objItemValue) {objSelect. options [I]. text = objItemText; break ;}} alert ("modified successfully") ;}else {alert ("this select does not exist") ;}}// 5. set the first Item of text = "paraText" in select to the selected function jsSelectItemByValue (objSelect, objItemText) {// determine whether var isExit = false; for (var I = 0; i; I ++) {if (objSelect. options [I]. text = objItemText) {objSelect. options [I]. selected = true; isExit = true; break;} // Show the result if (isExit) {alert ("selected successfully ");} else {alert ("this select does not exist") ;}// 6. set Item of value = "paraValue" in select to selected document. all. objSelect. value = objItemValue; // 7. obtain the value var currSelectValue = document of the selected item in the select statement. all. objSelect. value; // 8. the text var currSelectText = document. all. objSelect. options [document. all. objSelect. selectedIndex]. text; // 9. the Index var currSelectIndex = document. all. objSelect. selectedIndex; // 10. clear the select item document. all. objSelect. options. length = 0;

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.