HTML DOM 输入日期 stepDown() 方法
htmlweb developmentfront end technology更新于 2025/9/13 21:00:17
HTML DOM 输入日期 stepDown() 方法定义日期字段应减少的天数。
语法
以下是语法 −
使用数字调用 stepDown 方法,默认情况下该数字等于 1
inputDateObject.stepDown(number)
示例
让我们看一个 Input Date stepDown 方法的示例 −
<!DOCTYPE html>
<html>
<head>
<title>Input Date stepDown()</title>
</head>
<body>
<form>
<div>
Calendar: <input type="date" id="dateSelect" value ="2019-07-07">
</div>
</form>
<button onclick="changeStep(2)">Decrease by 2</button>
<button onclick="changeStep(3)">Decrease by 3</button>
<div id="divDisplay"></div>
<script>
var divDisplay = document.getElementById("divDisplay");
var inputDate = document.getElementById("dateSelect");
function changeStep(num){
if(num===2)
inputDate.stepDown(2);
else
inputDate.stepDown(3);
divDisplay.textContent = 'Current date decreased by: '+num;
}
</script>
</body>
</html>
输出
这将产生以下输出 −
点击"减少 2"按钮 −

点击"减少 3"按钮 −

相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

