The JQuery setting gets the value of comparison of an option in the drop down menu

  • 2020-03-30 03:39:08
  • OfStack

JQuery gets and sets the Select option

For the Select:

Get the text selected by select:

$(" # ddlRegType "). The find (" option: selected "). The text ();

Get the value selected by the select:

$(" # ddlRegType "). Val ();

Gets the index selected by select:

$(" # ddlRegType "). The get (0). SelectedIndex;

Set up the select:

Set the index selected by select:

$(" # ddlRegType "). The get (0). SelectedIndex = index; //index is the index value

Set the selected value of select:


$( " #ddlRegType  " ).attr( " value " , " Normal " );
$( " #ddlRegType  " ).val( " Normal " );
$( " #ddlRegType  " ).get(0).value = value;

Set the text selected by select:


var count=$( " #ddlRegType option " ).length;
for(var i=0;i<count;i++)
{ if($( " #ddlRegType  " ).get(0).options[i].text == text)
{
$( " #ddlRegType  " ).get(0).options[i].selected = true;
break;
}
}

To empty the Select:

$(" # ddlRegType "). The empty ();


Related articles: