简体   繁体   English

如何在onchange MooTools选项中添加/删除所选属性?

[英]How to add/remove selected attribute to option onchange MooTools?

Here is my fiddle: http://jsfiddle.net/tE6Wv/7/ 这是我的小提琴: http : //jsfiddle.net/tE6Wv/7/

I need to add or remove from previously selected option attribute selected="selected" to the option on change with moo , but the html is never added. 我需要添加或从先前选择的选项属性中将selected="selected"到使用moo进行更改的选项中,但是永远不会添加html。

I am slo creating the menu with moo but selected value is not taken 我正在用moo创建菜单,但未采用所选值

var firstoption = new Element('option', { 
    'selected':'selected', 
    'value':"myValue" 
}

or 要么

var firstoption = new Element('option', {
    'selected': true,
    'value': "myValue"
} 

none of these work 这些都不起作用

Appreciate any help. 感谢任何帮助。 Thank you! 谢谢!

FWIW, you can change your fiddle to confirm that selected is already being changed for you as such. FWIW,您可以更改小提琴以确认所选内容已被更改。 I've assigned id's to the 2 options just to make it a little easier to tell: 我已将ID分配给了2个选项,只是为了使其更容易分辨:

html change to include id attributes on the 2 link options: html更改为在2个链接选项上包括id属性:

<select id="menu" onchange="location.href=this.value">
    <option value="">Go to..</option>
    <option id="link1" value="#">Link</option>
    <option id="link2" value="#">Link</option>
</select>​​​​​​​​​​​

js to show the selected changes already: js已显示所选更改:

$('menu').addEvent('change',function() {
    alert(document.getElementById('link1').selected);
    alert(document.getElementById('link2').selected);
});​

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

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