第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

根據(jù)另一個 HTML5 日期值設(shè)置 HTML5 日期字段最小值

根據(jù)另一個 HTML5 日期值設(shè)置 HTML5 日期字段最小值

富國滬深 2023-10-30 15:56:39
我正在嘗試根據(jù)另一個 HTML5 日期輸入中設(shè)置的值來設(shè)置 HTML5 日期輸入的最小日期。因此,如果您在第一個日期字段中選擇 2020 年 4 月 3 日,則min第二個日期輸入的值將為 2020 年 4 月 3 日。我嘗試過使用第一個日期輸入的值,但這不起作用。任何建議都會很棒。var today = new Date();var dd = today.getDate();var mm = today.getMonth() + 1; //January is 0!var yyyy = today.getFullYear();if (dd < 10) {  dd = '0' + dd}if (mm < 10) {  mm = '0' + mm}today = yyyy + '-' + mm + '-' + dd;document.getElementById("fDate").setAttribute("min", today);function myFunction() {  var minToDate = document.getElementById("fDate").value;  document.getElementById("fDate").setAttribute("min", minToDate);}<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script><input type="date" id="fDate" onBlur="myFunction()"><input type="date" id="tDate">
查看完整描述

3 回答

?
holdtom

TA貢獻1805條經(jīng)驗 獲得超10個贊

將 fdate 更改為 tdate


document.getElementById("fDate").setAttribute("min", minToDate);


document.getElementById("tDate").setAttribute("min", minToDate);

var today = new Date();

var dd = today.getDate();

var mm = today.getMonth() + 1; //January is 0!

var yyyy = today.getFullYear();


if (dd < 10) {

  dd = '0' + dd

}


if (mm < 10) {

  mm = '0' + mm

}


today = yyyy + '-' + mm + '-' + dd;

document.getElementById("fDate").setAttribute("min", today);


function myFunction() {

  var minToDate = document.getElementById("fDate").value;

  document.getElementById("tDate").setAttribute("min", minToDate);

}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

<input type="date" id="fDate" onBlur="myFunction()">

<input type="date" id="tDate">


查看完整回答
反對 回復(fù) 2023-10-30
?
白豬掌柜的

TA貢獻1893條經(jīng)驗 獲得超10個贊

您想要將最小值設(shè)置為第二個日期選擇器,因此您需要獲取該元素:


function myFunction() {

  var minToDate = document.getElementById("fDate").value;

  document.getElementById("tDate").setAttribute("min", minToDate);

}


查看完整回答
反對 回復(fù) 2023-10-30
?
守著一只汪

TA貢獻1872條經(jīng)驗 獲得超4個贊

你的邏輯不起作用,因為你將 min 設(shè)置為fDate,而不是tDate。


您還應(yīng)該避免使用內(nèi)聯(lián)onX事件屬性,因為它們已經(jīng)過時并且不再是良好的做法。請改用不顯眼的事件處理程序。由于接受 Date 對象,因此可以進一步簡化邏輯min,因此您不需要修改 Date 對象來形成字符串。


還值得注意的是,該min設(shè)置不會阻止用戶輸入該值之前的日期。它僅在提交表單時用于驗證,正如您在下面的示例中Submit單擊按鈕時看到的那樣。


let fDate = document.querySelector('#fDate');

let tDate = document.querySelector('#tDate');


fDate.addEventListener('change', function() {

  tDate.min = this.value;

});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

<form>

  <input type="date" id="fDate" />

  <input type="date" id="tDate" />

  <button>Submit</button>

</form>


查看完整回答
反對 回復(fù) 2023-10-30
  • 3 回答
  • 0 關(guān)注
  • 203 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號