Jquery summary of selec operation

 


<select class="selector">
  <option value="pxx">中国</option>
</select>

1, set value is pXX item selected
     $ ( "Selector.") Val ( "pXX");.
2, set the text to pXX the item is selected
    . $ ( ". Selector") find ( "option [text = 'pxx '] ".) attr (" selected ", true);
    there is a bracket usage, the equal sign in front of the parentheses is the name of the attribute, without quotes. In many cases, the use of brackets can cause the logic becomes very simple.
3, to obtain the currently selected item value
    $ ( "Selector.") Val ();.
4, to obtain the currently selected item text
    $ ( "Selector.") The Find ( "the Option: the Selected") text ();..

The SELECT cascade, i.e., the second select value changes with the value of the first select selected 
as: $ ( "Selector1.") change (function () {.
     // first empty second
      $ ( "selector2." ) .empty ();
     // a practical application, option here are generally used to generate a plurality of loop
      var Option = $ ( "<Option>") Val (. 1) .text ( "pXX");.
      $ ( ".selector2").

Dynamically add option

$("#selectId").append("<option value='"+value+"'>"+text+"</option>");
delete

$("#selectedId option").remove();

 

Guess you like

Origin www.cnblogs.com/min-yu/p/10927675.html