character - Trouble selecting an item in a SELECT box with jQuery with a quot -
I am getting a hidden form with the list on which I need to select this option when the user Wants to see the form. I was using var assignini = 'people's name';
jQuery ('# edit-form' option [value = '+ option +']: first '). Attr ("selected", "selected");
I tried to do this but it is not working because the value in the option tag is also not specified with \ \ n, so it will not get any matching
JQuery ('# edit-form option [value =' + option.replace (/ \ '/,' \\\ '') + ']: first'). Attr ("selected", "selected");
Is this the only option for me?
jQuery ('# edit-form option') each (function () {If (jQuery (this) .val () == option) {jQuery (this) .attr ("selected "," Selected "); return false;}});
A test page
& lt; Html & gt; & Lt; Top & gt; & Lt; Script src = "http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js" & gt; & Lt; / Script & gt; & Lt; Script & gt; // test wars var option1 = "option two"; Var option 2 = "option" "var option = option 2; $ (document) .ready (function () {$ ('# edit-form [name = select1]' option) .for each (function () {if ( $ (This) .val () == option} {$ ($ ('# edit-form [name = select2] option [value =' + option + ']: first'). Atter ("" selected "," $ ('Option', 'selected'); option = option. Location (/ \ '/,' \\\ ''); $ ('# edit-form [name] = Selection 3] option [value = '+ option +']: first ') .attr ("selected", "selected");}); & lt; / script> gt; & lt; / head & gt; Lt; body & gt; & lt; form id = "edit-form" & gt; & lt; select name = select1 & gt; & lt; options Type value = "option one" & gt; Option one & lt; / option & gt; & lt; option value = "option two" & gt; option two & lt; / option & gt; & lt; option value = " Option two "option 2
About:
jQuery (' # Edit option [value = "'+ + option +" "]: first') .triter (" selected "," selected ");
"
And note the use of '
characters. Examples are all valid strings: <"valid" string "valid" string "" / > but not
"Not valid" string "'valid not' 'string' '
You can also see it with Syntax Highlighter.
Edit:
If I use it then works for me:
$ (' # Edit-form select [name = "Select3"] option [value = "'+ + option +"]]'.) First () .triter ("selected", "selected");
Note: I use instead of
and select the appropriate .
: first select [name = "select3"]
. That you use the appropriate jQuery selectors
Comments
Post a Comment