w2toolbar.enable
更新日: 2018-09-07
enable(id1, [id2], ...)
idを指定してアイテムを有効化します。 戻り値はintegerです。
- id: string
- 有効化するアイテムのid。
説明
ツールバーに.items配列が存在していなければなりません。 ツールバーアイテムは.idプロパティで識別されます。 このメソッドは、元々無効だった*1アイテムが有効化された場合に、その個数を返します。
*1 "元々無効"かどうかは判定しておらず、指定したアイテムの個数を返すようです。
ツールバーが以下のように定義されている場合、
$('#toolbar').w2toolbar({
    name  : 'toolbar',
    items : [
        { type: 'check',  id: 'item1', text: 'Check', img: 'icon-page', checked: true },
        { type: 'radio',  id: 'item3',  group: '1', text: 'R-1', img: 'icon-add', disabled: true },
        { type: 'radio',  id: 'item4',  group: '1', text: 'R-2', img: 'icon-add' },
        { type: 'menu',   id: 'item5', text: 'Drop Down',
            items: [
                { id: 'id1', text: 'menu 1' },
                { id: 'id2', text: 'menu 2' },
                { id: 'id3', text: 'menu 3' },
            ]
        }
    ]
});以下のように指定します。
w2ui['toolbar'].enable('item3', 'item4');メニューのアイテムを有効化することもできます。
w2ui['toolbar'].enable('item5:id2', 'item5:id3');デモ
ボタンをクリックすると、'check1'と'check3'を有効化します。
JavaScript
$('#toolbar').w2toolbar({
  name  : 'mytoolbar',
  items : [
    { type: 'check',  id: 'item1', text: 'check1', disabled: true},
    { type: 'check',  id: 'item2', text: 'check2', disabled: true},
    { type: 'check',  id: 'item3', text: 'check3' },
  ],
});
$('#get-result').on('click', function(){
  var resutl = w2ui['mytoolbar'].disable('item1', 'item3');
  document.getElementById('result').innerHTML = result + '個を有効化';
});HTML
<button id="get-result">実行</button>
<div>
  <span id="result"></span>
</div>
<div id="toolbar"></div>© 2017.  .
.
Code licensed under theMIT License. Documentation licensed underCC BY 3.0.
このコンテンツはvitmalinaによるw2ui.toolbarドキュメントを翻訳/改変したものです。