【问题标题】:Get selected date of persianDate获取 persianDate 的选定日期
【发布时间】:2021-12-30 13:05:56
【问题描述】:

使用此代码,我可以将所选日期作为 unix。 jsfiddle

  function getValue() {
      var date = $('#example').data("DateTimePicker").date();
      if( date ){
        alert(date.unix());
      }
    }

PersianDate 怎么样,我想将选定的日期作为 unix。 jsfiddle

【问题讨论】:

  • 有什么问题?我修好了你的小提琴jsfiddle.net/mplungjan/fbo09p25
  • @mplungjan 谢谢,你能用按钮做吗?所以在点击期间我想访问数据。使用您的代码,我应该为每个 persianDate 提供一个输入,只是为了获取它的数据。

标签: javascript jquery date unix datepicker


【解决方案1】:

您可以通过在 persianDatepicker 实例上使用 getState 方法来做到这一点,如下所示:

var pd = $('#example').persianDatepicker({
  autoClose: true,
  // other options
});

function showUnix() {
  const state = pd.getState();
  alert(state.selected.unixDate);
}
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script>
<script src="https://babakhani.github.io/PersianWebToolkit/doc/lib/persian-date/dist/persian-date.js"></script>
<script src="https://babakhani.github.io/PersianWebToolkit/doc/lib/persian-datepicker/dist/js/persian-datepicker.js"></script>
<link href="https://unpkg.com/persian-datepicker@latest/dist/css/persian-datepicker.min.css" rel="stylesheet" />

<input type="text" id="example" class="initial-value-type-example inline-example leapyear-algorithmic">
<button onclick="showUnix()">show unix</button>

【讨论】:

    猜你喜欢
    • 2020-12-06
    • 1970-01-01
    • 1970-01-01
    • 2013-06-21
    • 2017-05-26
    • 1970-01-01
    相关资源
    最近更新 更多