jquery Implementation Select Automatically selects default values

Source: Internet
Author: User

 // // the Select target Auto Select value extension  plugin // author:hotboy// --------------------------------------------------------------------- ----- //  (function  ($)  {     $.extend ($.fn, {                   //          AutoSelect: function  (Options)  {              // default options of plugin              var defaults = {                  atr:   "Val",                  filter:  "SELECT"              }              // deep copy $.extend (ISDEEPCOPY,DEFAULT_SRC, Ext1,ext2,ext3,ext4,......);              var new_options =  $.extend (true, defaults, options);                                        var  $this  = $ (this);               $this. Each (function  ()  {                  var  $t  = $ (This);                &nbsP; // alert ($t. Prop ("TagName". toLocaleUpperCase ()));                  if  (New_options.filter.toLocaleUpperCase ()  !=   $t. Prop ("TagName")  {                       $t. Val ($t. attr (DEFAULTS.ATR));                  }              })          }      });  }) (JQuery);


Front-end invocation mode

Js function


$ (function () {

$ ("tag Selector"). AutoSelect ({ATR: "Checked value Attribute", Filter: "Filters the label type, does not execute bindings,"});

});


==========================================================================================

Example:


Select Label

<select val= "0" >

<option value= "-1" >--Select Gender--</option>

<option value= "0" > Men </option>

<option value= "1" > Women </option>

</Select>


$ (function () {

$ ("Select[val]"). AutoSelect ();

});

===========================================================================================

Here is just a very simple jquery extension demo, hope can help you ~

jquery Implementation Select Automatically selects default values

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.