开发者

jQuery if children have value, make them selected

I have a PHP value called per_page which I'm carrying on to a jQuery function.

I want the jQuery function to search the <select id="thisForm"> element for any <option> with the text() value equal to per_page.

I then want the function to make that <option> selected, so it appears like this: <option selected>.

I didn't know how to use this() or whatever once I've found the text() value.

Solution:

$(document).ready(function() {
   var i = 'whatever your per_page valu开发者_StackOverflow中文版e is';
   $("#changeForm option[value=" + i +"]").attr("selected",true);
});


I think that this should work:

$('#thisForm option:contains("per_page")').attr('selected',true);

Using contains().

JS Fiddle demo of concept.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜