我正在嘗試在輸入日期中設(shè)置文本,但那里沒有顯示任何內(nèi)容。數(shù)據(jù)類型有問題嗎?<!DOCTYPE html><html><body><table> <tr> <td id="invoice"> 2020-09-22 </td> </tr></table> <select id="decisionList"> <option></option> <option>Payment date</option></select><div id="choice"></div><script>document.addEventListener("change", function () { var decisionList = document.getElementById("decisionList"); var selectedOptionIndex = decisionList.options[decisionList.selectedIndex].index; var invoiceDate = document.getElementById("invoice"); var invoiceDateText = invoiceDate.textContent; var finalChoice = document.getElementById("choice"); switch(selectedOptionIndex) { case 0: finalChoice.innerHTML='<input type="date">' break; case 1: finalChoice.innerHTML='<input type="date" value="' + invoiceDateText + '">' //here is a problem break; default: finalChoice.innerHTML='' } })</script></body></html>我還嘗試根據(jù)傳遞的文本創(chuàng)建新日期: var newDate = new Date(invoiceDateText);但也不起作用。如您所見,我正在通過 2020-09-22(從 td 開始)那么問題出在哪里?
如何將日期/文本傳遞給 <input type="date">?
楊魅力
2023-05-19 16:04:06