一、单选按钮(Radio Buttons)
<input type="radio"> 标签定义了表单的单选框选项:
html
<form action="">
<input type="radio" name="sex" value="male">男<br>
<input type="radio" name="sex" value="female">女
</form>
二、 radio c++接口定义:
third_party\blink\renderer\core\html\forms\radio_input_type.h
third_party\blink\renderer\core\html\forms\radio_input_type.cc
cpp
namespace blink {
class RadioInputType final : public BaseCheckableInputType {
public:
CORE_EXPORT static HTMLInputElement* NextRadioButtonInGroup(HTMLInputElement*,
bool forward);
RadioInputType(HTMLInputElement& element)
: BaseCheckableInputType(Type::kRadio, element) {}
bool ValueMissing(const String&) const;
private:
void CountUsage() override;
ControlPart AutoAppearance() const override;
void WillUpdateCheckedness(bool new_checked) override;
String ValueMissingText() const override;
void HandleClickEvent(MouseEvent&) override;
void HandleKeydownEvent(KeyboardEvent&) override;
void HandleKeyupEvent(KeyboardEvent&) override;
bool IsKeyboardFocusable(
Element::UpdateBehavior update_behavior =
Element::UpdateBehavior::kStyleAndLayout) const override;
bool ShouldSendChangeEventAfterCheckedChanged() override;
ClickHandlingState* WillDispatchClick() override;
void DidDispatchClick(Event&, const ClickHandlingState&) override;
bool ShouldAppearIndeterminate() const override;
HTMLInputElement* FindNextFocusableRadioButtonInGroup(HTMLInputElement*,
bool);
HTMLInputElement* CheckedRadioButtonForGroup() const;
};
template <>
struct DowncastTraits<RadioInputType> {
static bool AllowFrom(const InputType& type) {
return type.IsRadioInputType();
}
};
} // namespace blink