最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to set option selected when using jqtransform on select element - Stack Overflow

programmeradmin2浏览0评论

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 :)

发布评论

评论列表(0)

  1. 暂无评论