jquery日常总结

1.checkbox操作

1.判断 有id的单个checkbox是否被选中

方法一 用attr属性

$("#showPoint").attr("checked")=="checked" 注意此处返回的是checked or undefined

方法二 用is方法
$("#showPoint").is(":checked")==true 注意此处返回的是true or false

<input type="checkbox" id="showPoint" name="showPoint" checked>

2.checkbox的全选/取消全选以及取选中个数

全选

$("input[type=checkbox][name=stuIds]").attr("checked","true");

取消全选

$("input[type=checkbox][name=stuIds]").removeAttr("checked");

取选中的个数

$("input[type=checkbox][name=stuIds]:checked").length

2.radio操作

1.取被选中的radio的值

$("input[type='radio'][name='radiotest']:checked").val() 当没有选中任务一个时 undefined 选中了一个就取到他的value值

<input type="radio" name="radiotest" value="1" >
<input type="radio" name="radiotest" value="2" >

 

3.select操作

1.取select选中的text

$(#selecttest option:selected').text();
或$("#selecttest").find('option:selected').text();

 

2.取select选中的value值
或$("#testSelect").val();

 

<select id="selecttest" name="selecttest" >
    <option value="">--请选择--</option>
    <option value="123">--123--</option>
    <option value="456">--456--</option>
</select>

 3.清空重置select框

 

$("#subjectId").empty(); 清空select

//重置select
$("#subjectId").append("<option value=''>--请选择--</option>");

sublist是一个列表
if(null!=sublist){
     for(var i=0;i<sublist.length;i++){
     jQuery("#subjectId").append("<option value='"+sublist[i].id+"' title='"+sublist[i].subjectName+"'>"+sublist[i].subjectName+"</option>");
      }
}

 <select name="subjectId" id="subjectId" onChange="doQuery();" class="input-sel100">
    <option value="">--请选择--</option>
 </select>

 

4.iframe操作

取得同个窗口下的其他iframe里的元素值

例子 取 iframe id=listFrame的 中的 id为showPoint的checkbox框 并判断是否被选中

jQuery("#listFrame").contents().find("#showPoint").attr("checked")=="checked" 

 

1. 在父窗口中操作 选中IFRAME中的所有单选钮
$(window.frames["iframe1"].document).find("input:radio").attr("checked","true");

2. 在IFRAME中操作 选中父窗口中的所有单选钮
$(window.parent.document).find("input:radio").attr("checked","true");

父窗口想获得IFrame中的Iframe,就再加一个frames子级就行了,如:
$(window.frames["iframe1"].frames["iframe2"].document).find("input:radio").attr("checked","true");

 

5.跨iframe checkbox操作

声明一个ids数组用来存放被选中的checkbox的value的数组

var ids = new Array();
 var j=0;

然后取id=rightFrame的iframe里的name=ids 类型是checkbox 的选中的元素数组
 var chk = jQuery("#rightFrame").contents().find("input[type='checkbox'][name='ids']:checked");

最后把元素数组的value值赋值给ids数组
 for(var i=0;i<chk.length;i++){
  if(chk[i].checked){
   ids[j]=chk[i].value;
   j++
  }
 } 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值