HTML DOM Input Week type 属性

htmlweb developmentfront end technology更新于 2025/9/11 13:32:17

HTML DOM Input Week type 属性返回/设置输入周的类型。

语法

以下是语法 −

  • 返回字符串值
inputWeekObject.type
  • 将 type  设置为字符串值
inputWeekObject.type = stringValue

字符串值

此处,“stringValue” 可以是以下 −

stringValue详细信息
week定义输入类型为 week
datetime-local定义输入类型为 datetime-local
checkbox定义输入类型为 checkbox
text它定义了输入类型为文本

示例

让我们看一个Input Week type属性的示例 −

<!DOCTYPE html>
<html>
<head>
<title>Input Week type</title>
<style>
   form {
      width:70%;
      margin: 0 auto;
      text-align: center;
   }
   * {
      padding: 2px;
      margin:5px;
   }
   input[type="button"] {
      border-radius: 10px;
   }
</style>
</head>
<body>
<form>
<fieldset>
<legend>Week-type</legend>
<label for="WeekSelect">Event:
<input type="week" id="WeekSelect">
</label>
<input type="button" onclick="getTypeOfInput()" value="What type of input?">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
   var divDisplay = document.getElementById("divDisplay");
   var inputWeek = document.getElementById("WeekSelect");
   function getTypeOfInput() {
      divDisplay.textContent = 'Type of input Expected: '+inputWeek.type;
   }
</script>
</body>
</html>

输出

这将产生以下输出 −

点击"什么类型的输入?"按钮之前 −

点击"什么类型的输入?"按钮之后 −


相关文章


有用资源