HTML DOM Input Date type 属性
htmlweb developmentfront end technology
HTML DOM Input Date type 属性返回/设置输入日期的类型。
语法
以下是语法 −
- 返回字符串值
inputDateObject.type
- 将 type 设置为字符串值
inputDateObject.type = stringValue
字符串值
这里,"stringValue"可以是以下 −
| stringValue | 详细信息 |
|---|---|
| date | 它定义了输入类型为 date |
| radio | 它定义了输入类型为 radio |
| checkbox | 它定义输入类型为复选框 |
示例
让我们看一个输入日期类型属性的示例 −
<!DOCTYPE html>
<html>
<head>
<title>Input Date type</title>
</head>
<body>
<form>
<div>
Calendar: <input type="date" id="dateSelect" value="2017-05-01">
</div>
</form>
<button onclick="changeType()">Change Type</button>
<div id="divDisplay"></div>
<script>
var divDisplay = document.getElementById("divDisplay");
var inputDate = document.getElementById("dateSelect");
divDisplay.textContent = 'Input type: '+ inputDate.type;
function changeType(){
if(inputDate.type === 'date'){
var currDate = inputDate.value;
inputDate.type = 'text';
inputDate.value = currDate;
}
divDisplay.textContent = 'Input type: '+ inputDate.type;
}
</script>
</body>
</html>
输出
这将产生以下输出 −
点击"更改类型"按钮之前 −

点击"更改类型"按钮之后 −

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

