一、Input 类型: number
number 类型用于应该包含数值的输入域。
您还能够设定对所接受的数字的限定:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>test</title>
</head>
<body>
<form action="demo-form.php">
数量 ( 1 到 5 之间): <input type="number" name="quantity" min="1" max="5">
<input type="submit">
</form>
<p><b>注意:</b>Internet Explorer 9 及更早 IE 版本不支持 type="number" 。</p>
</body>
</html>
二、c++定义:
third_party\blink\renderer\core\html\forms\number_input_type.h
third_party\blink\renderer\core\html\forms\number_input_type.cc
namespace blink {
class ExceptionState;
class NumberInputType final : public TextFieldInputType {
public:
explicit NumberInputType(HTMLInputElement& element)
: TextFieldInputType(Type::kNumber, element) {}
bool TypeMismatchFor(const String&) const;
private:
void CountUsage() override;
void SetValue(const String&,
bool value_changed,
TextFieldEventBehavior,
TextControlSetValueSelection) override;
double ValueAsDouble() const override;
void SetValueAsDouble(double,
TextFieldEventBehavior,
ExceptionState&) const override;
void SetValueAsDecimal(const Decimal&,
TextFieldEventBehavior,
ExceptionState&) const override;
bool TypeMismatch() const override;
bool SizeShouldIncludeDecoration(int default_size,
int& preferred_size) const override;
StepRange CreateStepRange(AnyStepHandling) const override;
void HandleKeydownEvent(KeyboardEvent&) override;
void HandleBeforeTextInsertedEvent(BeforeTextInsertedEvent&) override;
Decimal ParseToNumber(const String&, const Decimal&) const override;
String Serialize(const Decimal&) const override;
String LocalizeValue(const String&) const override;
String VisibleValue() const override;
String ConvertFromVisibleValue(const String&) const override;
String SanitizeValue(const String&) const override;
void WarnIfValueIsInvalid(const String&) const override;
bool HasBadInput() const override;
String BadInputText() const override;
String ValueNotEqualText(const Decimal& value) const override;
String RangeOverflowText(const Decimal& maxmum) const override;
String RangeUnderflowText(const Decimal& minimum) const override;
String RangeInvalidText(const Decimal& minimum,
const Decimal& maximum) const override;
bool SupportsPlaceholder() const override;
void MinOrMaxAttributeChanged() override;
void StepAttributeChanged() override;
bool SupportsSelectionAPI() const override;
};
template <>
struct DowncastTraits<NumberInputType> {
static bool AllowFrom(const InputType& type) {
return type.IsNumberInputType();
}
};
} // namespace blink