How jquery dynamically selects option under Select, based on a particular value

Source: Internet
Author: User

Here, for example, select the current month by default:

Html:

<select name= "Monat" id= "Monat" >
    <option value= "1" >1</option>
    <option value= "2" >2 </option>
    <option value= "3" >3</option>
    <option value= "4" >4</option>
    <option value= "5" >5</option>
    <option value= "6" >6</option>
    <option value= "7" >7</option>
    <option value= "8" >8</option>
    <option value= "9" >9</option>
    <option value= "Ten" >10</option>
    <option value= "One" >11</option>
    <option Value= "A" >12</option>
</select> Month

First gets the current month and dynamically selects the corresponding option under the current month for select

$ (function () {
    var date=new date;
    var Yue = date.getmonth () +1;
    $ ("#MONAT"). Find ("Option[value = '" +yue+ "]"). attr ("Selected", "selected");

This allows the current month to be selected by default when the file load completes.


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.