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。

1.添加属性名称该属性就会生效应该使用prop.
2.是有true,false两个属性使用prop.
3.其他则使用attr

参考:

http://www.cnblogs.com/KeenLeung/p/3799895.html

checkbox选中相关问题总结的更多相关文章

  1. easyui 》 radio取值,checkbox取值,select取值,radio选中,checkbox选中,select选中

    获取一组radio被选中项的值var item = $('input[@name=items][@checked]').val();获取select被选中项的文本var item = $(" ...

  2. jquery radio取值,checkbox取值,select取值,radio选中,checkbox选中,select选中

    jQuery获取Select选择的Text和Value: 语法解释: 1. $("#select_id").change(function(){//code...}); //为Se ...

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

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

  4. 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 ...

  5. jquery设置和获得checkbox选中问题

    1.设置checkbox选中: //选中多选框 checkbox=$("#agentinfo input[name='veri[]']"); //循环多选框中的值 checkbox ...

  6. checkbox的相关知识点

    1.获取单个checkbox选中项(三种写法)$("input:checkbox:checked").val()或者$("input:[type='checkbox']: ...

  7. checkbox 选中个数

    背景: 1 Choose1 全选checkbox ,选中此checkbox,子列表的checkbox全部为选中状态. 2 在子列表中如果去掉一个checkbox则Choose1 的全选状态也改为不选中 ...

  8. # li鼠标移入移出,点击,变背景色,变checkbox选中状态

    移入移出背景色改变和点击背景色改变,两者是否相互覆盖? 若移出背景色恢复,影响点击事件的背景色改变,会产生效果为: 点击时,背景色改变,并且checkbox选中 鼠标移开后,checkbox仍选中,但 ...

  9. 设置checkbox选中,设置radio选中,根据值设置checkbox选中,checkbox勾选

    设置checkbox选中,设置radio选中,根据值设置checkbox选中,checkbox勾选 >>>>>>>>>>>>&g ...

随机推荐

  1. python标准库之argparse

    argparse的使用 argparse 是 Python 内置的一个用于命令项选项与参数解析的模块,通过在程序中定义好我们需要的参数,argparse 将会从 sys.argv 中解析出这些参数,并 ...

  2. 卷积神经网络(matlab实现)

    卷积神经网络是看matlab 的一个toolbox入的门: https://github.com/rasmusbergpalm/DeepLearnToolbox 还有一篇原理推导文献,全是公式: ht ...

  3. vc++基础班[26]---进程的相关操作

      ①.ShellExecute 进行进程的创建,属于 shell api: //int iRet = (int)ShellExecute(m_hWnd, _T("open"), ...

  4. WPA简介

    摘选自 https://www.sohu.com/a/199641521_683126 WPA 全名 WI-FI Protected Access, 有WPA 和WPA2两个标准,是一种保护无线网络的 ...

  5. mongodb内建角色

    MongoDB内建角色 数据库用户角色:read.readWrite; 数据库管理角色:dbAdmin.dbOwner.userAdmin: 集群管理角色:clusterAdmin.clusterMa ...

  6. kali sudo apt install 无法定位软件包

    在etc/apt   的sources.list 添加镜像源 debhttp://http.kali.org/kali kali-rolling main non-free contrib 或 deb ...

  7. JMeter3.2生成图形化HTML报告

    JMeter3.0引入了Dashboard Report,用于生成HTML页面格式图形化报告的扩展模块. 该模块支持通过两种方式生成多维度图形化测试报告: 在JMeter性能测试结束时,自动生成本次测 ...

  8. CentOS 7 服务器之间ssh无密码登录、传输文件

    在Linux服务器之间使用ssh命令向另一个Linux服务器发送执行指令是需要输入密码     ssh登录提供两种认证方式:口令(密码)认证方式和密钥认证方式.其中口令(密码)认证方式是我们最常用的一 ...

  9. RedHat Linux关闭防火墙的命令

    获得root 控制权限.在“#”下操作. 查看防火墙状态. systemctl status firewalld 临时关闭防火墙命令.重启电脑后,防火墙自动起来. systemctl stop fir ...

  10. Confluence 6 增加和减少你许可证的用户数

    增加你许可证的用户数 如果你使用的用户数超过你许可证允许的用户数的话,你的 Confluence 实例将会变成为只读. 只读的意思是没有用户可以创建和编辑内容,直到你的用户数满足你的许可证需求为止. ...