HTML DOM Input Radio 类型的属性
HTML DOM Input radio 类型的属性与 type=”radio” 的 input 元素相关联。它始终会为 input radio 元素返回 radio。
语法
以下是 radio 类型属性的语法 −
radioObject.type
示例
让我们看一个 radio 类型属性的示例 −
<!DOCTYPE html>
<html>
<body>
<h1>Input radio type Property</h1>
<form>
FRUIT:
<input type="radio" name="fruits" id="Mango">Mango
<br>
</form>
<p>Get the above input element type by clicking the below button</p>
<button type="button" onclick="radioType()">GET Type</button>
<p id="Sample"></p>
<script>
function radioType() {
var P=document.getElementById("Mango").type;
document.getElementById("Sample").innerHTML = "The type for the input field is: "+P ;
}
</script>
</body>
</html>输出
这将生成以下输出 −

单击类型按钮 GET −

我们首先在 form 中创建了一个 type=”radio” 的 input 元素,name=”fruits”,id=”Mango” −
<form> FRUIT: <input type="radio" name="fruits" id="Mango">Mango </form>
然后,我们创建了“GET 类型”按钮,用户单击后将执行 radioType() 方法 −
<button type=”button” onclick="radioType()">GET Type</button>
radioType() 方法使用 getElementById() 方法获取 input 元素,并将它的 type 属性值分配给变量 P。然后使用 innerHTML 属性,将这个变量显示在 id 为“Sample”的段落中 −
function getType() {
var P = document.getElementById("Mango").type;
document.getElementById("Sample").innerHTML = "The type for the input field is : "+P;
}
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP