The CSS input[value=whatever] selector doesn't seem to match against input.value. What am I missing?

前端 未结 2 1615
逝去的感伤
逝去的感伤 2021-01-27 17:04

N.B.: I should note that the proper solution to this is to just use the \'placeholder\' attribute of an input, but the question still stands.

Another N.B.: Since, as Qu

相关标签:
2条回答
  • 2021-01-27 17:25

    The value attribute sets the default value for the field.

    The value property sets the current value for the field. Typing in the field also sets the current value.

    Updating the current value does not change the value attribute.

    Attribute selectors only match on attribute values.

    0 讨论(0)
  • 2021-01-27 17:49

    There are new pseudo classes for matching a number of properties of an input element

    • :valid
    • :invalid
    • :in-range
    • :out-of-range
    • :required

    A required element with no value set to it will match against :invalid. If you insist on using the value instead of placeholder, you could simply add a pattern or a customValidity function to force your initial value to be counted as invalid.

    0 讨论(0)
提交回复
热议问题