目前,我的api鏈接是通過選擇當前的年和月進行動態的。
示例。 APILINK.../202109
這部分很好...... 但我想做的是用一個日期選擇器來改變API鏈接的最后部分(年和月),我不確定如何才能做到這一點。
我目前的代碼:
const timehsheetUrl = "API LINK"/span>
const today = new Date()。
const date = today.getFullYear() ('0' ( today. getMonth() 1)).slice(-2) 。
const settings = {
"async"。true,
"crossDomain": true,
"url": timesleetUrl date,
"method": "GET",
"headers"/span>: {}。
}
uj5u.com熱心網友回復:
其易于使用的jquery日期選擇器;
在日期選擇腳本中應該回傳所選日期的年月日
將輸出存盤在變數和格式中>>下面的代碼將幫助你
。//html代碼,在head部分使用JQURY UI CDN。
<input type="text" id="calendar" name="date1"/>
//html代碼。
<script>/span>
$('#calendar').datepicker({
dateFormat: 'yy-m-d',
inline: true,
onSelect: function(dateText, inst) {
var date = $(this).datepicker('getDate') 。
日 = date.getDate()。
月 = date.getMonth() 1,
year = date.getFullYear()。
// alert(day '-' month '-' year);
//下面是你的結果。
alert( "api link is " "APILINK.../" year month) 。
}
});
</script>
uj5u.com熱心網友回復:
不,你不需要使用datepicker插件,而插件更方便。
下面是一個使用默認HTML日期輸入的例子。
。const timesleetUrl = "API LINK"/span>;
const today = new Date();
function urlDateSuffix(_date) {
return _date.getFullYear() ('0' (_date. getMonth() 1)).slice(-2)。
}
let settings = {
"async"。true,
"crossDomain": true,
"url": timesleetUrl urlDateSuffix(day)。
"method": "GET"。
"headers"/span>: {}。
}
console.log(設定)。
$(function() {
$('#datepicker'/span>).change(function() {
設定。 url = timesleetUrl urlDateSuffix(new Date(this. value))。)
console.log(設定)。
alert(settings.url)。
});
});
<script src="https://cdnjs. cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>/span>
< input type="date" id="datepicker">
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" class="snippet-box-edit snippet-box-result" frameborder="0"></iframe>
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/321652.html
標籤:
