我正在尝试在输入日期中设置文本,但那里没有显示任何内容。数据类型有问题吗?
<!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>
我还尝试根据传递的文本创建新日期:
var newDate = new Date(invoiceDateText);
但也不起作用。如您所见,我正在通过 2020-09-22(从 td 开始)那么问题出在哪里?
HUH函数
SMILET
相关分类