html性别按钮如何写

html-css07

html性别按钮如何写,第1张

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()