JQuery(二)

  还是觉得有必要对最近做过的项目中常见的一些jquery用法做一个总结,也算是加深一点点印象吧。以下内容没有任何逻辑,想到了即写出来而已!

  1.jquery遍历读取table中第一列的数据

1 for(var i=1;i<$("#department").find("tr").length;i++){
2         department += $("#department tr:eq("+i+") td:nth-child(1)").text() + ",";
3     }

  2.jquery循环遍历读取选中的checkbox的数据

1     var strcode= new Array();
2     var strdesc = new Array();
3     $("input#checkbox").each(function(){ 
4         if($(this).attr("checked")){
5             strcode.push($(this).attr("_code"));
6             strdesc.push($(this).attr("_desc"));
7         }
8     });

  3.jquery选中radio

1 if(result.isAllProduct == true){
2     $("input:radio[value='yes']").attr('checked','true');
3 }else{
4     $("input:radio[value='no']").attr('checked','true');
5 }

  4.jquery动态改变html

1 //method one
2 $("#unProducts").append(stradd);
3 
4 //method two
5 $("input#addconditionone").click(function(){
6         $(StrUtil.str1).appendTo('#addconditionone1');  
7 });

  5.jquery操作选择框

1 var scopeid = $("#activityscope").find("option:selected").val();

   6.jquery siblings()用法 :获取匹配集合元素的所有同胞元素

1 //p 元素的所有类名为 "selected" 的所有同胞元素
2 $("p").siblings(".selected").css("background", "yellow");
3 
4 $j('div.detail_menu li').mouseover(function(){
5       var $jthis = $j(this);
6       $jthis.addClass('curr').siblings().removeClass('curr');
7 }

 7.jquery toggle用法

1 $j("#select-hold").toggle(function(){
2             $j(this).html("<b></b>收起").attr("class","close");
3             $j("#select-brand .content_extend div").slice(15).attr("class","");
4         },function(){
5             $j(this).html("<b></b>展开").attr("class","open");
6             $j("#select-brand .content_extend div").slice(15).attr("class","hidden");
7     });

 

 

  

posted @ 2012-11-28 23:54  matrix.skygirl  阅读(301)  评论(0编辑  收藏  举报