Thursday, 15 July 2010

jquery - Select option by text -


I'm having trouble choosing some default values ​​that come via AJAX

Here's a Bella's:

Here's the code:

HTML:

  & lt; Div & gt; & Lt; = "Condition" for label id = "conditionLabel" & gt; Condition: & lt; / Label & gt; & Lt; Select ID = "Status" & gt; & Lt; Option selected = "true" style = "display: none;" & Gt; Select & lt; / Options & gt; & Lt; / Select & gt; & Lt; / Div & gt;   

JS:

  var conditions = [{id: 1, name: "new"}, {id: 2, name: "good"} , {Id: 3, name: "poor"}]; $ .each (conditions, function (key, value) {var cond = '& lt; option value =' '+ value.id +' "& gt; '+ value.name +'  '$ (' #condition '). Attachment (; cond);}); $ ('# Position option [text = "new"]). Ether ('selected', 'selected');   

The last line that is causing me trouble, I want to select the option based on the text

You can use in: :

  $ ('# condition option: in it (" new') '') Is included. 'Selected', true);   

or .filter () :

  $ (' Filter (function () {return this.text === 'new';}) .prop ('selected', true);   

: There will also be included news , so I .filter ()

No comments:

Post a Comment