checkbox选中相关问题总结
html:
<input type="checkbox" name="fruit" id="apple">苹果
<input type="checkbox" name="fruit" checked id="orange">橘子
<input type="checkbox" name="fruit" id="banana">香蕉
一、原生js
//选中
document.getElementById("apple").checked=true; document.getElementById("orange").setAttribute('checked','checked');
document.getElementById("banana").setAttribute('checked',true);
//取消选中
document.getElementById("orange").checked=false;
//判断是否选中
if(document.getElementById("CheckedAll").checked)
取消选中不能用:
document.getElementById("banana").setAttribute('checked',false);
二、使用jquery
Jquery1.7.2.js
//选中
$("#apple").attr('checked',true);
//判断是否选中
$("#apple").is(":checked");//true
$("#orange").is(":checked");//true
$("#banana").is(":checked");//false
//取消选中
$("#orange").attr('checked',false);
1.7.2中不能用prop属性。
jquery-1.9.1.min.js
//选中
$("#apple").attr('checked',true);
$("#banana").prop('checked',true);
三、prop()和attr()区别
.prop()方法和.attr()方法,单从字面上很难区分。在汉语中properties和attributes都有表示“属性”的意思。
jquery 1.6+增加了.prop()方法
<input type="checkbox" checked="checked" />
在1.6版中,调用方法$(":checkbox").attr("checked")方法将返回"checked"值,而不是true.
而之前的版本则会返回true/false。
参考:
http://www.cnblogs.com/KeenLeung/p/3799895.html
checkbox选中相关问题总结的更多相关文章
- easyui 》 radio取值,checkbox取值,select取值,radio选中,checkbox选中,select选中
获取一组radio被选中项的值var item = $('input[@name=items][@checked]').val();获取select被选中项的文本var item = $(" ...
- jquery radio取值,checkbox取值,select取值,radio选中,checkbox选中,select选中
jQuery获取Select选择的Text和Value: 语法解释: 1. $("#select_id").change(function(){//code...}); //为Se ...
- 【jQuery获取下拉框select、单选框radio、input普通框的值和checkbox选中的个数】
radio单选框:name属性相同 <input type="radio" id="sp_type" name="p_type" va ...
- checkbox 选中、取值处理
[1].[代码] checkbox 选中.取值处理 跳至 [1] ? 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 ...
- jquery设置和获得checkbox选中问题
1.设置checkbox选中: //选中多选框 checkbox=$("#agentinfo input[name='veri[]']"); //循环多选框中的值 checkbox ...
- checkbox的相关知识点
1.获取单个checkbox选中项(三种写法)$("input:checkbox:checked").val()或者$("input:[type='checkbox']: ...
- checkbox 选中个数
背景: 1 Choose1 全选checkbox ,选中此checkbox,子列表的checkbox全部为选中状态. 2 在子列表中如果去掉一个checkbox则Choose1 的全选状态也改为不选中 ...
- # li鼠标移入移出,点击,变背景色,变checkbox选中状态
移入移出背景色改变和点击背景色改变,两者是否相互覆盖? 若移出背景色恢复,影响点击事件的背景色改变,会产生效果为: 点击时,背景色改变,并且checkbox选中 鼠标移开后,checkbox仍选中,但 ...
- 设置checkbox选中,设置radio选中,根据值设置checkbox选中,checkbox勾选
设置checkbox选中,设置radio选中,根据值设置checkbox选中,checkbox勾选 >>>>>>>>>>>>&g ...
随机推荐
- 消息队列:JMS之基本概念介绍
摘要:The Java Message Service (JMS) API is a messaging standard that allows application components bas ...
- codeforces 461div.2
A Cloning Toys standard input/output 1 s, 256 MB B Magic Forest standard input/output 1 s, 256 M ...
- atom 的使用插件
emmet # html补全minimap # 源码预览图linter # 语法检查file-icons # 文件图标docblockr # 注释块autoclose-html # 自动闭合html标 ...
- MD5加密算法工具类
import java.math.BigInteger; import java.security.MessageDigest; import java.security.NoSuchAlgorith ...
- 【原创】大数据基础之Logstash(2)应用之mysql-kafka
应用一:mysql数据增量同步到kafka 1 准备mysql测试表 mysql> create table test_sync(id int not null auto_increment, ...
- Windows平台下,Java性能分析工具VisualVM的Tomcat8的配置
VisualVM在JDK6版本及以上已经自带这个应用. 位置:C:\Program Files (x86)\Java\jdk1.8.0_60\bin\jvisualvm.exe 在Windows环 ...
- oracle里面用sql做报表并带小计合计常用到的函数
1-- DECODE函数是Oracle PL/SQL是功能强大的函数之一,假设我们想给职员加工资,其标准是:工资在8000元以下的将加20%:工资在8000元以上的加15%,通常的做法是,先选出记录 ...
- VBS计时器2
打开计时器,如果点击暂停,会显示你刚才事物所用的时间(以分钟为单位) dim c //控制循环 c= vbyes while c<>vbno dim a a= 60*hour(now)+m ...
- CM5.15安装kafka
cm主节点执行: [root@dip001 kafka]#ll KAFKA-.jar KAFKA---el7.parcel KAFKA---el7.parcel.sha1 manifest.json ...
- 数字、ip转换python实现
# 数字 ==> ip # 数字范围[0, 255^4] >>> num2ip = lambda x: '.'.join([str(x/(256**i)%256) for i ...