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>
1、新建一个html文件,命名为test.html。
2、在test.html文件内,引入jquery.min.js库文件,成功加载该文件,才能使用jquery中的方法。
3、在test.html文件内,在p标签内,使用input标签创建两个radio选项,分别是男,女两个选项。
4、在test.html文件内,使用button标签创建一个按钮,按钮名称为“获取选中的值”。
5、在test.html文件中,给button按钮绑定onclick点击事件,当按钮被点击时,执行getradio()函数。
6、在js标签中,创建getradio()函数,在函数内,通过input元素的“:checked”选择器获得已选中的radio对象,使用val()方法获得radio的值。最后,使用alert()方法将值输出。
你好,这是一个单向选择按钮,如选择男女男性:<input type="radio" name="gentle" checked="checked" value="male"><br/>
女性:<input type="radio" name="gentle" value="female">
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)