单选框

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. [SimpleOJ238]宝藏探寻

    题目大意: 给你一棵带点权的n个结点的树,有m次询问,每次从树上删掉一条路径(u,v),问删掉每条路径后各个连通块权值和的平方之和. 每次询问是独立的. 思路: 首先对树遍历一遍求出每棵子树的权值和. ...

  2. 【8.30校内测试】【找规律模拟】【DP】【二分+贪心】

    对于和规律或者数学有关的题真的束手无策啊QAQ 首先发现两个性质: 1.不管中间怎么碰撞,所有蚂蚁的相对位置不会改变,即后面的蚂蚁不会超过前面的蚂蚁或者落后更后面的蚂蚁. 2.因为所有蚂蚁速度一样,不 ...

  3. Codeforces VK Cup 2015 - Qualification Round 1 D. Closest Equals 离线线段树 求区间相同数的最小距离

    D. Closest Equals Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/prob ...

  4. Codeforces Round #305 (Div. 1) B. Mike and Feet 单调栈

    B. Mike and Feet Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/547/pro ...

  5. uoj 67 新年的毒瘤 tarjan求割点

    #67. 新年的毒瘤 Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://uoj.ac/problem/67 Description 辞旧迎新之际 ...

  6. PAT甲级1095. Cars on Campus

    PAT甲级1095. Cars on Campus 题意: 浙江大学有6个校区和很多门.从每个门口,我们可以收集穿过大门的汽车的进/出时间和车牌号码.现在有了所有的信息,你应该在任何特定的时间点告诉在 ...

  7. Eclipse配置Struts2问题:ClassNotFoundException: org...dispatcher.ng.filter.StrutsPrepareAndExecuteFilter

    我的解决方案 一开始,我是依照某本教材,配置了User Libraries(名为struts-2.2.3, 可供多个项目多次使用), 然后直接把struts-2.2.3引入过来(这个包不会真正的放在项 ...

  8. 【spring cloud】spring cloud 使用feign调用,1.fallback熔断器不起作用,2.启动报错Caused by: java.lang.ClassNotFoundException: com.netflix.hystrix.contrib.javanica.aop.aspectj.Hystri解决

    示例GitHub源码地址:https://github.com/AngelSXD/springcloud 1.首先使用feign调用,需要配置熔断器 2.配置熔断器需要将熔断器注入Bean,熔断器类上 ...

  9. pytest文档5-fixture之conftest.py

    前言 前面一篇讲到用例加setup和teardown可以实现在测试用例之前或之后加入一些操作,但这种是整个脚本全局生效的,如果我想实现以下场景: 用例1需要先登录,用例2不需要登录,用例3需要先登录. ...

  10. s:iterator数据累加示例代码

    <s:set var="xs_heji" value="0" /> <s:set var="km_heji" value= ...