html-radio-1.1

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/caishu1995/article/details/88536663
<input type="radio" name="sex" value="0" />
<input type="radio" name="sex" value="1" />

    同组中的radio通过设置相同的name,控制单选

    如果要人为控制选中,可以人为给radio控件加checked属性

    以下是取值的方法。

<html>
<head>
	<title>radio测试</title>
</head>
<body>
	<input type="radio" name="sex"  value="0" />
	<input type="radio" name="sex"  value="1" />

	<button onclick="getData()">取值</button>

	<script>
		function getData(){
			var list = document.getElementsByName("sex");
			for(var i = 0; i < list.length; i++){
				if(list[i].checked){
					alert(list[i].value);
					return;
				}
			}
		}
	</script>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/caishu1995/article/details/88536663
1.1