month()
更新日: 2018-09-04
month()
// 使い方
chance.month()「月」をランダムに返します。
chance.month();
=> 'January'デフォルトでは、月名(英語)を返します。
rawを指定すると、name、short_name、numeric、daysで構成されたオブジェクト全体を返します。
chance.month({raw: true});
=> {name: 'October', short_name: 'Oct', numeric: '10'}デモ
ボタンを押すと、月オブジェクトをランダムに表示します。
結果:
JavaScript
var button = document.getElementById('get-result');
button.addEventListener('click', function() {
  var chance = new Chance(),
      month  = chance.month({raw: true}),
      result = document.getElementById('result'),
      ul, li;
  ul = document.createElement('ul');
  Object.keys(month).forEach(function(i) {
    li = document.createElement('li');
    li.textContent = month[i];
    ul.appendChild(li);
  });
  if (result.firstChild !== null) {
    result.removeChild(result.firstChild);
  }
  result.appendChild(ul);
}, false);
HTML
<button id="get-result">結果表示</button>
<div>
  <span>結果:</span>
  <span id="result"></span>
</div>© 2015 Victor Quinn Released under the MIT license
このコンテンツはVictor Quinn(victorquinn)によるChanceドキュメントを翻訳/改変したものです。