📜  HTML | DOM 输入单选对象

📅  最后修改于: 2021-11-07 08:34:14             🧑  作者: Mango

Input Radio 对象用于访问创建type=”radio”的输入元素。

句法:

  • 访问输入元素类型=“radio”。
    document.getElementById("ID");
  • 创建输入元素 type=”radio”。
    var GFG = document.createElement("INPUT");
    x.setAttribute("type", "radio");
    

属性值:

Value Description
autofocus It states if a radio button should automatically get focus when the page loads.
checked It returns the checked state of a radio button.
defaultChecked It returns the default value of the checked attribute.
defaultValue It returns the default value of a radio button.
disabled It returns if the radio button is disabled, or not.
form It returns a reference to the form that contains the radio button.
name It returns the value of the name attribute of a radio button.
required It returns if the radio button must be checked before submitting a form.
type It returns which type of form element the radio button is.
value It returns the value of the value attribute of the radio button.

示例 1:访问输入对象 type=”radio”



  

    

  

    

GeeksforGeeks

       

HTML DOM Input Radio Object

       

An example access a Radio Button

    Radio Button:             

Click the button to uncheck it.

                    

输出:

点击前:

点击后:

示例 2:创建输入元素 type=”radio”。



  

    

  

    

GeeksforGeeks

       

HTML DOM Input Radio Object   

    

Click to create a Radio Button.   

            
          

输出:

点击前:

点击后:

支持的浏览器:

  • 谷歌浏览器
  • 火狐浏览器
  • 边缘
  • 苹果浏览器
  • 歌剧