The SELECT tag simulates the placeholder property with a general operation (most importantly, an iOS item is selected for compatibility)

Source: Internet
Author: User

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)

Related Article

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.