单选框input:radio
单选框
CreateTime--2017年5月15日11:40:04
Author:Marydon
四、单选框
(一)语法
<input type="radio"/>
(二)实现点击文字,选中对应按钮的两种方式
方式一:label标签体包住单选框标签
<label class="radioStyle"><input type="radio" class="radioStyle" name="test1" value="0" checked/>男</label>
<label class="radioStyle"><input type="radio" class="radioStyle" name="test1" value="1"/>女</label
方式二:label标签体只包住文本
<input type="radio" class="radioStyle" name="test2" value="0" id="yes"/><label for="yes" class="radioStyle">是</label>
<input type="radio" class="radioStyle" name="test2" value="1" id="no" checked/><label for="no" class="radioStyle">否</label>
注意:
1.同一组单选框必须使用同一个name;
2.单选框没有默认选中值,要想默认选中,必须声明checked属性;
3.方式二label标签的for属性的值必须与单选框的id值保持一致。
(三)单选框的onchange事件
示例:
通过单选框的选中状态来实现其他元素的显示或隐藏
第一部分:HTML
是否替诊
<label style="cursor: pointer;">
<input type="radio" name="REPLACE_TZ" value="0" style="cursor: pointer;"
onchange="$('#REPLACE_TZ_NAME').show();"/>
是
</label>
<label style="cursor: pointer;">
<input type="radio" name="REPLACE_TZ" value="1" style="cursor: pointer;"
onchange="$('#REPLACE_TZ_NAME').hide();" checked/>
否
</label>
替诊医生名称
<select id="REPLACE_TZ_NAME" name="REPLACE_TZ_NAME" style="display: none;">
<option value="">请选择</option>
<option value="1">医生一</option>
<option value="2">医生二</option>
<option value="3">医生三</option>
</select>
注意:
1.同一组单选框必须使用同一个name;
2.同一组的每个单选框都得绑定onchange事件;
3.单选框及复选框的onchange事件在IE浏览器运行时存在的问题:
在IE中却不会正常执行,即选中或取消复选框不会立即执行
原因:
IE会等到单选框或复选框失去焦点之后才会触发onchange事件
解决方案:
绑定点击事件,手动触发失焦、聚焦事件
第二部分:JAVASCRIPT
/**
* 判断是否是IE浏览器,支持IE6-IE11
*/
function isIE() { //ie?
if (!!window.ActiveXObject || "ActiveXObject" in window)
return true;
else
return false;
}
window.onload = function () {
if(!isIE()) return;
/*
* 是否替诊,单选框绑定点击事件
*/
$('input:radio[name=REPLACE_TZ]').click(function () {
this.blur();
this.focus();
});
}
实现效果:
单选框被选中时,显示隐藏的下拉框,取消选中时,再隐藏下拉框。
UpdateTime--2017年6月13日14:51:06
(四)单选框设置默认选中项
单选框没有默认选中项,如果需要指定选项选中,需要在该单选框添加属性:checked
举例:
<label class="radioCss">
<input name="CANCEL_CONSULT" type="radio" value="1" checked/>
不再需要
</label>
<label class="radioCss">
<input name="CANCEL_CONSULT" type="radio" value="2" />
患者转院
</label>
<label class="radioCss">
<input name="CANCEL_CONSULT" type="radio" value="3" />
其他
</label>
2019年12月23日
jQuery获取选中单选框的值
var sex = $("input[name='LSSEX']:checked").val();
相关推荐:
单选框input:radio的更多相关文章
- 自动化测试基础篇--Selenium单选框(Radio)复选框(CheckBox)
摘自:https://www.cnblogs.com/sanzangTst/p/7686602.html 一.什么是单选框.复选框? 二.单选框:radio 三.复选框:checkbox 四.判断是否 ...
- 如何获取select中的value、text、index相关值 && 如何获取单选框中radio值 && 触发事件 && radio 默认选中
如何获取select中的value.text.index相关值 select还是比较常用的一个标签,如何获取其中的内容呢? 如下所示: <select id="select" ...
- form中 单选框 input[type="radio"] 分组
在form中有时候需要给单选框分组,这种情况下 可以通过给单选框设置相同的name来进行分组: <html> <head> <title> </title&g ...
- 关于input单选框的radio属性
最近在做前端页面的时候遇到一个问题(后端php猴子前端不怎么写) 我写了一段代码: <form action=""> <label for=&quo ...
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 表单:复选框(Checkbox)和单选框(Radio)
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- 针对bootstrap内联单选框input与文字不能居中对齐的解决办法
1.html代码 <div > <label class="checkbox-inline first-label"> <input type=&qu ...
- 前端 HTML form表单标签 input标签 type属性 radio 单选框
<input type="radio"> 单选框 适用于 选择性别按钮网页等 <!DOCTYPE html> <html lang="en& ...
- 【jQuery获取下拉框select、单选框radio、input普通框的值和checkbox选中的个数】
radio单选框:name属性相同 <input type="radio" id="sp_type" name="p_type" va ...
- 纯CSS3来自定义单选框radio与复选框checkbox
单选框(radio)自定义样式 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 3 ...
随机推荐
- 20162327WJH《程序设计与数据结构》课程总结
20162327<程序设计与数据结构>课程总结 一.每周作业链接汇总 预备作业1:第一篇博客主要谈论了对本学期学习的展望,树立了一个目标. 预备作业2:简单的谈了谈自己的优势和一些成功的案 ...
- VIM选项配置说明
选项配置说明 选项书写格式 选项说明 :se[t] 显示所有被改动的选项 :se[t] all 显示所有非 termcap 选项 :se[t] termcap 显示所有 termcap 选项 :se[ ...
- 将mnist数据集存储到本地文件
参考文章: http://www.csuldw.com/2016/02/25/2016-02-25-machine-learning-MNIST-dataset/ import numpy as np ...
- php 安装 Redis 扩展
开发环境安装包为:wamp3.1.0,安装成功后 wamp/bin 目录下有php以下几个版本: 这里以php7.1.9为例进行redis扩展安装,其他php版本也是一样的. 进行安装 step 1: ...
- unix/linux中如何在vi编辑器中方便的跳转到首行和末行?
1.跳转到首行,:0/:1 2.跳转到末行,shift +g/G/:$
- gridview 空数据绑定
private void getDataBind() { DataTable dt = new DataTable(); dt.Columns.Add("id"); dt.Colu ...
- Circuit level-shifts ac signals
AC signals can emanate from many sources, and many of these sources are incompatible with the most p ...
- ELM320 OBD(PWM) to RS232 Interpreter
http://elmelectronics.com/DSheets/ELM320DS.pdf
- Eclipse:The superclass javax.servlet.http.HttpServlet was not found on the Java Build Path
我们在用Eclipse进行Java web开发时,可能会出现这样的错误:The superclass javax.servlet.http.HttpServlet was not found on t ...
- windows系统上安装与使用Android NDK r8d(一)
什么是NDK? NDK 提供了一系列的工具,帮助开发者快速开发C(或C++)的动态库,并能自动将so 和 java 应用一起打包成apk.这些工具对开发者的帮助是巨大的. NDK 集成了交叉编译器,并 ...