1. For uniform styling, it is often necessary to simulate placeholder
<select>
<option Disabled selected hidden> Please select </option>
<option>what</option>
<option>the</option>
<option>hell</option>
</select>
2.select selected value and a value to be selected (iOS compatible)
<select style= "font-size:60px" >
<option>2</option>
<option>5 year </option>
<OPTION>10 year </option>
<OPTION>20 year </option>
</select>
<select style= "font-size:50px" id= "select_id" >
<option value= "1" > Annual delivery </option>
<option value= "2" > Followers </option>
</select>
A gets the selected value:
Gets the text selected by the Select:
$ ("SELECR"). EQ (0). Find ("option:selected"). Text ();
Gets the value selected by select:
$ ("SELECR"). EQ (0). Val ();
Gets the index selected by the select:
$ ("SELECR") [0].selectedindex;
B Set Select
var itext= $ ("SELECR"). EQ (0). Find ("option:selected"). Text ();
$ (' select '). EQ (1). Find ("Option[value = '" +itext+ "']"). Prop ("Selected", "Selected");
Before the use of is attr, but found that iOS can not, did not think as long as the attr replaced prop there is no compatibility problem, iOS is really torture goblin Ah!
There are also $ (' select '). EQ (1). val (IText);
$ (' select '). EQ (1). Get (0). Value =itext;
The following two kinds of do not do a compatibility test, according to the truth is no problem because it is modified before the code, dare not change
C Clear Select:
$ (' select '). EQ (1). empty ();
D increase or decrease the opacity term for select
$ ' (#select_id '). Append ("<option value= ' value ' >text</option>"); Add an option
$ (#select_id '). Prepend ("<option value= ' 0 ' > Please select </option>"); Insert an option in front
$ ("#select_id option:last"). Remove (); Remove the most indexed value option
$ ("#select_id option[index= ' 0 ']"). Remove ();//delete option with index value 0
$ ("#select_id option[value= ' 3 ']"). Remove (); Delete option with a value of 3
$ ("#select_id option[text= ' 4 ']"). Remove (); Delete option with a text value of 4
The
Select tag simulates the placeholder property with a generic operation (most importantly, an iOS item is selected for compatibility)