单选框

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的更多相关文章

  1. 自动化测试基础篇--Selenium单选框(Radio)复选框(CheckBox)

    摘自:https://www.cnblogs.com/sanzangTst/p/7686602.html 一.什么是单选框.复选框? 二.单选框:radio 三.复选框:checkbox 四.判断是否 ...

  2. 如何获取select中的value、text、index相关值 && 如何获取单选框中radio值 && 触发事件 && radio 默认选中

    如何获取select中的value.text.index相关值 select还是比较常用的一个标签,如何获取其中的内容呢? 如下所示: <select id="select" ...

  3. form中 单选框 input[type="radio"] 分组

    在form中有时候需要给单选框分组,这种情况下 可以通过给单选框设置相同的name来进行分组: <html> <head> <title> </title&g ...

  4. 关于input单选框的radio属性

    最近在做前端页面的时候遇到一个问题(后端php猴子前端不怎么写) 我写了一段代码: <form action="">        <label for=&quo ...

  5. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 表单:复选框(Checkbox)和单选框(Radio)

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  6. 针对bootstrap内联单选框input与文字不能居中对齐的解决办法

    1.html代码 <div > <label class="checkbox-inline first-label"> <input type=&qu ...

  7. 前端 HTML form表单标签 input标签 type属性 radio 单选框

    <input type="radio"> 单选框 适用于 选择性别按钮网页等 <!DOCTYPE html> <html lang="en& ...

  8. 【jQuery获取下拉框select、单选框radio、input普通框的值和checkbox选中的个数】

    radio单选框:name属性相同 <input type="radio" id="sp_type" name="p_type" va ...

  9. 纯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 ...

随机推荐

  1. Python入门,以及简单爬取网页文本内容

    最近痴迷于Python的逻辑控制,还有爬虫的一方面,原本的目标是拷贝老师上课时U盘的数据.后来发现基础知识掌握的并不是很牢固.便去借了一本Python基础和两本爬虫框架的书.便开始了自己的入坑之旅 言 ...

  2. 四、python之 if while for

    一.if条件判断 if 条件判断: 逻辑操作…… …… else: 逻辑操作…… 其中"判断条件"成立时(非零),则执行后面的语句,而执行内容可以多行,以缩进来区分表示同一范围. ...

  3. 第一章 -- Java性能调优概述

    写在前面的话:读书破万卷,编码如有神--------------------------------------------------------------------主要内容包括: 1.概述 2 ...

  4. VK Cup 2016 - Qualification Round 2 C. Road Improvement dfs

    C. Road Improvement 题目连接: http://www.codeforces.com/contest/638/problem/C Description In Berland the ...

  5. 厄拉多塞筛法和普通方法求素数表(python实现)

    厄拉多赛筛法(sieve of Eratosthenes): 想要得到一个不大于N的数所有素数,可以先找到不超过根号N的所有素数,设2 = p1 < p2 < ......<pk ≤ ...

  6. PHP 基础函数(二)数组的内部指针

    current($arr);  返回数组中的当前单元pos($arr);  返回数组中的当前单元key($arr);  返回数组中当前单元的键名prev($arr);  将数组中的内部指针倒回一位ne ...

  7. CentOS 6.9开启iptables的日志实现调试

    系统日志配置在CentOS 5上叫syslog,而在CentOS 6上叫rsyslog(增强版的syslog),CentOS 5上的配置文件在/etc/syslog.conf下,而CentOS 6在/ ...

  8. 一、 Log4E插件下载

    下载地址:http://log4e.jayefem.de/content/view/3/2/ 二.安装Log4E插件 将下载下来的压缩包解压缩,如下图所示: 解压缩生成的[de.jayefem.log ...

  9. Activex 数字签名

    本次使用makecert的命令如下: makecert -sv online.pvk -n "CN=中国在线" -ss My -r -b 01/01/1900 -e 01/01/9 ...

  10. linux ifconfig

    Linux and Unix ifconfig command Quick links About ifconfig Syntax Examples Related commands Linux an ...