何も選択しない場合、YUI3ではJavascript Select Boxの更新が必要ですか?

StackOverflow https://stackoverflow.com/questions/1201898

  •  05-07-2019
  •  | 
  •  

質問

YUI 3を使用して、誰かが[すべて選択]をクリックできるようにします。または「選択なし」を選択してください次に、選択ボックスですべてのアイテムを選択するか、すべてのアイテムを選択解除します。これが私のコードです:

// 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が機能するため、それぞれの「選択」属性を手動で削除し、追加し直す必要がありました。

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 );
   });
});
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top