简体   繁体   English

使用YUI3在IE中设置选择值

[英]Set value of a select in IE using YUI3

I have a select box and I need to both set the selected value and issue a change event with javascript. 我有一个选择框,我需要设置选择的值并使用javascript发出更改事件。

In Firefox, the following works with no problem: 在Firefox中,以下内容可以正常使用:

Y.one('#my_select_box').set('value', STEP_VALUES);
Y.one('#my_select_box').simulate('change');

No such luck in IE (IE7 in this case). IE中没有这种运气(在本例中为IE7)。 The selected's value does not even change. 所选值甚至不会改变。 I have tried using 'selectedIndex' instead of 'value' too. 我也尝试过使用“ selectedIndex”而不是“ value”。

Any ideas? 有任何想法吗?

I didn't have success with the suggested answer, however I did have success with. 建议的答案我没有成功,但是我确实有成功。

Y.one("#object").set("selectedIndex", 1);

Where 1 is the index to be selected. 其中1是要选择的索引。

A reasonable answer is mySelect.query('option[value=foo]').set('selected', true); 一个合理的答案是mySelect.query('option[value=foo]').set('selected', true); , however according this ticket it looks like the set('value', value) approach should work on the select tag itself, so I'm still unsure about that (I'm using YUI 3.1.1), so I'm still interested in any comments. ,但是根据这张票证 ,看起来set('value', value)方法应该可以在select标记本身上使用,所以我仍然不确定(我使用的是YUI 3.1.1),所以我仍然对任何评论感兴趣。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM