admin管理员组

文章数量:1326337

How to set option selected when using jqtransform on select element.

I'm using jqtransform for my form , and I want to set appropriate option value to be selected when I'm retrieving saved data from database.

How to set option selected when using jqtransform on select element.

I'm using jqtransform for my form , and I want to set appropriate option value to be selected when I'm retrieving saved data from database.

Share Improve this question asked Jul 9, 2012 at 19:47 AnushkaAnushka 2,4341 gold badge18 silver badges14 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

I believe you would set the value of select the same way as without using the jqTransform.

E.g.

$('#mySelect').val('myVal');

Edit:

Well, this is really ugly but should work:

var mySelect = $('#mySelect');

//find the current selected option
var myOption = mySelect.find('option[value='+mySelect.val()+']');

//find the index of that option
var index = $('#mySelect option').index(myOption);

//trigger the click on the corresponding jqTranfsform element
mySelect.prev('ul').find('li').eq(index).find('a').click();

You can call onchange event. jqtransform has change() method.

$('#mySelect').val('myVal').trigger('change');

It work's :)

本文标签: javascriptHow to set option selected when using jqtransform on select elementStack Overflow