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. Modify the text of value = "paravalue" in the select option to "paratext"
5. Set the first item of text = "paratext" in select to be selected.
6. Set the item of value = "paravalue" in select to be selected.
7. Obtain the value of the selected item in the SELECT statement.
8. Obtain the text of the selected select item.
9. Obtain the index of the selected item of the SELECT statement.
10. Clear select items
-------------------------------------------
// 1. Determine whether the select option contains an item with value = "paravalue"
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 to the select option
Function jsadditemtoselect (objselect, objitemtext, objitemvalue)
{
// Determine whether the object exists
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 );
Alert ("successfully added ");
}
}
// 3. delete an item from the select option
Function jsremoveitemfromselect (objselect, objitemvalue)
{
// Determine whether the object exists
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 item does not exist ");
}
}
// 4. Modify the text of value = "paravalue" in the select option to "paratext"
Function jsupdateitemtoselect (objselect, objitemtext, objitemvalue)
{
// Determine whether the object exists
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 item does not exist ");
}
}
// 5. Set the first item of text = "paratext" in select to be selected
Function jsselectitembyvalue (objselect, objitemtext)
{
// Determine whether the object exists
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 item does not exist ");
}
}
// 6. Set the item of value = "paravalue" in select to be selected
// Document. All. objselect. value = objitemvalue;
// 7. Obtain the value of the selected item of the SELECT statement.
// Var currselectvalue = Document. All. objselect. value;
// 8. Obtain the text of the selected item of the SELECT statement.
// Var currselecttext = Document. All. objselect. Options [document. All. objselect. selectedindex]. text;
// 9. Obtain the index of the selected item of the SELECT statement.
// Var currselectindex = Document. All. objselect. selectedindex;
// 10. Clear select items
// Document. All. objselect. Options. Length = 0;