簡體   English   中英

如何獲得多日期選擇器MDP的總天數

[英]How to get total of days Multidatepicker MDP

我從這里使用Multidatepicker MDP。
我想獲取用戶選擇的總天數,並將其放入輸入文本中。

例如,如果用戶選擇2天,則總數為2。
並在總輸入框中輸入一個文本。

這是我的JS

$('#mdp-demo').multiDatesPicker({
     numberOfMonths: [1,2],
     altField: '#altField',
     minDate: 2,
});

謝謝您的回答

使用您鏈接的站點中的信息: http : //dubrox.github.io/Multiple-Dates-Picker-for-jQuery-UI/#demo-ui-calendar-methods

您可以指定onSelect方法來響應選擇。
要獲取所選日期的數組,可以使用記錄的$('#mdp-demo').multiDatesPicker('getDates')

如果只考慮選定日期的數量,則可以簡單地使用數組的.length

我之前從未使用過此組件,但將以下文檔中的信息解析在一起似乎可以正常工作。 根據需要進行調整。

 $('#mdp-demo').multiDatesPicker({ numberOfMonths: [1, 2], altField: '#altField', minDate: 2, onSelect: function(){ $('#numberSelected').val($('#mdp-demo').multiDatesPicker('getDates').length); } }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link href="https://code.jquery.com/ui/1.12.1/themes/pepper-grinder/jquery-ui.css" rel="stylesheet" /> <link href="https://cdn.rawgit.com/dubrox/Multiple-Dates-Picker-for-jQuery-UI/master/jquery-ui.multidatespicker.css" rel="stylesheet" /> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script> <script src="https://cdn.rawgit.com/dubrox/Multiple-Dates-Picker-for-jQuery-UI/master/jquery-ui.multidatespicker.js"></script> <div> <span>Number Of Days Selected</span> <input id="numberSelected" type="text"/> </div> <br/> <div id="mdp-demo"></div> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM