<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <!--引入JQUERY包--> <script src="../jquery-1.11.2.min.js"></script> <style type="text/css"> </style> <title>无标题文档</title> </head> <in <body> <input type="checkbox" id="qx" /> 全选 <input type="checkbox" value="01" class="ck" /> <input type="checkbox" value="02" class="ck" /> <input type="checkbox" value="03" class="ck" /> <input type="checkbox" value="04" class="ck" /> <input type="checkbox" value="05" class="ck" /> <input type="radio" value="01" class="rd" name="a"/> <input type="radio" value="02" class="rd" name="a" /> <input type="radio" value="03" class="rd" name="a" /> <input type="radio" value="04" class="rd" name="a" /> <input type="radio" value="05" class="rd" name="a" /> <select id="sel"> <option value="1111">1111</option> <option value="2222">2222</option> <option value="3333">3333</option> </select> <input type="button" value="取选中" id="btn" /> <input type="button" value="取下拉" id="b1" /> <input type="button" value="取单选" id="b2" /> <script type="text/javascript"> //取复选框的选中值 $("#btn").click(function(){ var ck = $(".ck"); for(var i=0;i<ck.length;i++) { //判断选中 if(ck.eq(i).prop("checked")) { alert(ck.eq(i).val()); } } $("#b1").click(function(){ alert($("#sel").val()); })
单选按钮↓
$("#b2").click(function(){
var kk=$(".rd");
for(var i=0;i<kk.length;i++)
{
if(kk.eq(i).prop("checked"))
{
alert (kk.eq(i).val());
}
}
})
//全选 $("#qx").click(function(){ var xz = $(this).prop("checked"); $(".ck").prop("checked",xz) }) //js或jquery里面有数据存储的方式 //名字叫JSON /* var json = { code:"n001", name:"张三", js:{c:"p001",n:"回族"} }; //取值 alert(json["code"]); */ //去空格 /*var str = " hello "; str = str.trim(); //重要 alert(str.length); */ </script> </body> </html>