1. Determine whether the select option contains an item with value = "paravalue"
2. add an item to the select option
3. delete an item from the select option
4. Delete the selected items in the SELECT statement.
5. Modify the text of value = "paravalue" in the select option to "paratext"
6. Set the first item of text = "paratext" in select to be selected.
7. Set the item of value = "paravalue" in select to be selected.
8. Obtain the value of the selected item in the SELECT statement.
9. Get the text of the selected item of the SELECT statement.
10. Obtain the index of the selected item of the SELECT statement.
11. Clear select items
JS Code
-
- JS Code
-
- // 1. Determine whether the select option contains an item with value = "paravalue"
- FunctionJsselectisexititem (objselect, objitemvalue ){
-
- VaRIsexit =False;
-
- For(VaRI = 0; I <objselect. Options. length; I ++ ){
- If(Objselect. Options [I]. value = objitemvalue ){
-
- Isexit =True;
-
- Break;
-
- }
- }
-
- ReturnIsexit;
-
- }
-
-
- // 2. add an item to the select option
-
- FunctionJsadditemtoselect (objselect, objitemtext, objitemvalue ){
- // Determine whether the object exists
-
- If(Jsselectisexititem (objselect, objitemvalue )){
-
- Alert ("The value of this item already exists");
-
- }Else{
- VaRVaritem =NewOption (objitemtext, objitemvalue );
-
- Objselect. Options. Add (varitem );
-
- Alert ("Successfully added");
-
- }
-
- }
-
- // 3. delete an item from the select option
-
- FunctionJsremoveitemfromselect (objselect, objitemvalue ){
-
- // Determine whether the object exists
-
- If(Jsselectisexititem (objselect, objitemvalue )){
- For(VaRI = 0; I <objselect. Options. length; I ++ ){
-
- If(Objselect. Options [I]. value = objitemvalue ){
-
- Objselect. Options. Remove (I );
- Break;
-
- }
-
- }
-
- Alert ("Deleted");
-
- }Else{
- Alert ("This select item does not exist");
-
- }
-
- }
-
-
-
- // 4. Delete the selected items in the SELECT statement.
-
- FunctionJsremoveselecteditemfromselect (objselect ){
- VaRLength = objselect. Options. Length-1;
-
- For(VaRI = length; I> = 0; I --){
-
- If(Objselect [I]. Selected =True){
-
- Objselect. Options [I] =Null;
- }
-
- }
-
- }
-
-
- // 5. Modify the text of value = "paravalue" in the select option to "paratext"
-
- FunctionJsupdateitemtoselect (objselect, objitemtext, objitemvalue ){
- // Determine whether the object exists
-
- If(Jsselectisexititem (objselect, objitemvalue )){
-
- For(VaRI = 0; I <objselect. Options. length; I ++ ){
- If(Objselect. Options [I]. value = objitemvalue ){
-
- Objselect. Options [I]. Text = objitemtext;
-
- Break;
-
- }
- }
-
- Alert ("Modified successfully");
-
- }Else{
-
- Alert ("This select item does not exist");
-
- }
-
- }
-
- // 6. Set the first item of text = "paratext" in select to be selected
-
- FunctionJsselectitembyvalue (objselect, objitemtext ){
-
- // Determine whether the object exists
-
- VaRIsexit =False;
- For(VaRI = 0; I <objselect. Options. length; I ++ ){
-
- If(Objselect. Options [I]. Text = objitemtext ){
-
- Objselect. Options [I]. Selected =True;
- Isexit =True;
-
- Break;
-
- }
-
- }
-
- // Show the result
- If(Isexit ){
-
- Alert ("Selected");
-
- }Else{
-
- Alert ("This select item does not exist");
-
- }
- }
-
-
- // 7. Set the item of value = "paravalue" in select to be selected
-
- Document. All. objselect. value = objitemvalue;
-
-
- // 8. Obtain the value of the selected item of the SELECT statement.
-
- VaRCurrselectvalue = Document. All. objselect. value;
-
- // 9. Obtain the text of the selected item of the SELECT statement.
-
- VaRCurrselecttext = Document. All. objselect. Options
-
-
- [Document. All. objselect. selectedindex]. text;
-
-
- // 10. Obtain the index of the selected item of the SELECT statement.
-
- VaRCurrselectindex = Document. All. objselect. selectedindex;
-
- // 11. Clear select items
-
- Document. All. objselect. Options. Length = 0;
JS Code // 1. determine whether the select option contains the item Function jsselectisexititem (objselect, objitemvalue) {var isexit = false; For (VAR I = 0; I <objselect. options. length; I ++) {If (objselect. options [I]. value = objitemvalue) {isexit = true; break;} return isexit;} // 2. add an item Function jsadditemtoselect (objselect, objitemtext, objitemvalue) to the select option {// determine whether there is if (jsselectisexititem (objselect, objitemvalue )) {alert ("the value of this item already exists");} else {var varitem = New Option (objitemtext, objitemvalue); objselect. options. add (varitem); alert ("successfully added") ;}// 3. delete an item Function jsremoveitemfromselect (objselect, objitemvalue) from the select option {// determine whether there is if (jsselectisexititem (objselect, objitemvalue) {for (VAR I = 0; I <objselect. options. length; I ++) {If (objselect. options [I]. value = objitemvalue) {objselect. options. remove (I); break ;}} alert ("deleted successfully") ;}else {alert ("this select does not exist") ;}} // 4. delete the function jsremoveselecteditemfromselect (objselect) {var length = objselect. options. length-1; for (VAR I = length; I> = 0; I --) {If (objselect [I]. selected = true) {objselect. options [I] = NULL ;}}// 5. 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 <objselect. options. length; I ++) {If (objselect. options [I]. value = objitemvalue) {objselect. options [I]. TEXT = objitemtext; break ;}} alert ("modified successfully") ;}else {alert ("this select option does not exist") ;}}// 6. 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 <objselect. options. length; 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") ;}// 7. set item of value = "paravalue" in select to selected document. all. objselect. value = objitemvalue; // 8. obtain the value var currselectvalue = Document of the selected item in the SELECT statement. all. objselect. value; // 9. the text var currselecttext = document. all. objselect. options [document. all. objselect. selectedindex]. text; // 10. the index var currselectindex = document. all. objselect. selectedindex; // 11. clear the select item Document. all. objselect. options. length = 0;