Javascript在YUI3中选择Box必需刷新,何时选择无?
题
我正在使用YUI 3让某人点击“全选”或“选择无”然后让selectbox分别选择所有项目或取消选择所有项目。这是我的代码:
// This selects all
Y.on('click',function (e) {
selectBoxNode.get("options").each(function () {
this.removeAttribute('selected');
this.setAttribute('selected','selected');
});
}, selectAllNode
);
// This selects none
Y.on('click',function (e) {
selectBoxNode.get("options").each(function () {
this.setAttribute('selected','false');
this.removeAttribute('selected');
});
selectBoxNode.('selectedIndex',-1);
}, selectNoneNode
);
selectAllLink,selectNoneLink和selectBoxNode都是不言而喻的,正确返回节点。更新:selectAll有效,我必须手动删除每个'selected'属性并重新添加。
selectNoneLink不起作用:它只取消选择之前未选择的元素...尽管DOM检查显示selectedIndex属性确实已更改为-1,所以可能需要刷新?
任何帮助将不胜感激。如果在所有框架中都发生这种情况,那么也很高兴知道。
谢谢!
解决方案
这对我有用。
YUI().use('node', function(Y) {
Y.get('#unsel').on('click', function(e) {
Y.get('select').get('options').set('selected',false);
});
Y.get('#sel').on('click', function(e) {
Y.get('select').get('options').set('selected', true );
});
});
不隶属于 StackOverflow