input标签type写成radio单选。后面的文字自己添加,男女两个的input都要用相同的name值,因为只能选择一个。
<form action="/example/html/form_action.asp" method="get"><input type="radio" name="sex" value="male" /> Male<br />
<input type="radio" name="sex" value="female" /> Female<br />
<input type="submit" value="Submit" />
</form>
<input name="sex" type="radio" value="1" checked />男<input name="sex" type="radio" value="2" />女
获取更新之前的值:$("input[name='sex']:checked").val()
<!DOCTYPE html><html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
#formBox{
padding: 10px
width: 220px
height: 95px
border: 1px solid #ccc
position: absolute
top: 0
bottom: 0
left: 0
right: 0
margin: auto
}
#formBox div{
margin-top: 5px
}
#formBox div input{
box-sizing: border-box
padding: 5px
}
</style>
</head>
<body>
<div id="formBox">
<div>
<lable>账号</lable>
<input type="text" placeholder="请输入账号">
</div>
<div>
<lable>密码</lable>
<input type="text" placeholder="请输入密码">
</div>
<div>
<lable>性别</lable>
<label><input name="gender" type="radio" value="" />男 </label>
<label><input name="gender" type="radio" value="" />女 </label>
</div>
</div>
</body>
</html>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)