Will enter the default text type?

So, I have a rather random question, but here we go. I am working on some cheats with Javascript for a plugin. Say I have an input that looks like this:

<input type='cc' id='cc' class='' /> 

Obviously, the cc type is not a valid input type. Is html automatically by default an unknown type of text , or will it have an adverse effect?

+5
source share
3 answers

Quoting directly from W3.org

An input element without a specified type attribute is an input element with its type attribute set to "text" .

enter image description here

+6
source

If the value of the input type is unknown or not supported in the browser, it will default to "text".

+2
source

tl; dr: If you pass an invalid value for an enumerated attribute, an invalid default value will be used instead. If this does not exist, it will use the default value instead.

The input type attribute does not specify an invalid default value, but defines a default value that is text .

Therefore, using an invalid default value will be text .


From the WHATWG HTML specification:

2.4.3 Keywords and enumerated attributes

Some attributes are defined as taking one of a finite set of keywords. Such attributes are called enumerated attributes. [...] In addition, you can specify two default states. The first is an invalid default ; the second is missing by default .

[...]

If the attribute value does not match any of the specified keywords, but the attribute has an invalid default value, the attribute represents this state. Otherwise, if the attribute value does not match any of the keywords, but there is a specific default value defined by default, then this is the state represented by the attribute. Otherwise, there is no default value, and invalid values ​​mean that there is no state presented.

<input> indicates the missing default value, which is text :

Invalid default value is text state.

+1
source

Source: https://habr.com/ru/post/1235634/


All Articles