试图理解“枚举”的概念,因为它涉及全局HTML属性。
概念问题。
发布于 2022-11-06 14:13:09
枚举属性基本上是一个具有固定的可接受值集的属性。对于例如,<input>
标记的type属性可以有以下值之一:
还有很多,但你明白了。此属性可以具有一定数量的值。如果我输入的属性不是此预定义列表的一部分,则输入按钮将不知道如何处理它,并回退到它的默认行为,即输入类型“text”。
例:
.container {
display: flex;
flex-direction: column;
}
input {
width: 300px;
margin: 5px 10px;
}
<div class="container">
<input type="file">
<input type="text">
<input type="date">
<input type="range">
<input type="list">
</div>
正如您所看到的,list不是一个可接受的值,因此输入作为常规文本输入工作。
现在,如果枚举属性只能接受固定值,则根据该逻辑,将不会枚举可以接受任何值的属性。这方面的例子可以是标题、 data-*和value属性。可能还有很多,但这些都是我能从头顶上想到的。
使用前面的示例:
.container {
display: flex;
flex-direction: column;
}
input {
width: 300px;
margin: 5px 10px;
}
<div class="container">
<input type="file" title="No file chosen">
<input type="text" placeholder="Type some text">
<input type="text" placeholder="Enter something here">
<input type="date" title="Select a date">
</div>
我给了占位符和标题属性不同的值,但它们都是有效的。
希望这能回答你的问题
https://stackoverflow.com/questions/74323388
复制相似问题