Jquery學習筆記(一) 常用功能

1. checkbox 全選,反選,取值

 8  <SCRIPT LANGUAGE="JavaScript">
 9  <!--
10      $("document").ready(function(){
11          
12       $("#btn1").click(function(){
13           
14          $("[name='checkbox']").attr("checked",'true');//全選
15        
16       })
17       $("#btn2").click(function(){
18           
19          $("[name='checkbox']").removeAttr("checked");//取消全選
20        
21       })
22       $("#btn3").click(function(){
23           
24          $("[name='checkbox']:even").attr("checked",'true');//選中所有奇數
25        
26       })
27       $("#btn4").click(function(){
28           
29          $("[name='checkbox']").each(function(){
30              
31            
32              if($(this).attr("checked"))
33            {
34                $(this).removeAttr("checked");
35                
36            }
37            else
38            {
39                $(this).attr("checked",'true');
40                
41            }
42            
43          })
44        
45       })
46        $("#btn5").click(function(){
47       var str="";
48          $("[name='checkbox'][checked]").each(function(){
49              str+=$(this).val()+"\r\n";
50          })
51         alert(str);
52       })
53      })

        //上次取值的好像不行,所以就改成下面這個了:
              $("input[name='selectKnowledge']").each(function(){
    	      if($(this).attr("checked")==true)
    		knowledge+="&selectKnowledge=" + $(this).val();
          });

54  //-->
55  </SCRIPT>
56  
57 </HEAD>
58
59 <BODY>
60 <form name="form1" method="post" action="">
61   <input type="button" id="btn1" value="全選">
62   <input type="button" id="btn2" value="取消全選">
63   <input type="button" id="btn3" value="選中所有奇數">
64   <input type="button" id="btn4" value="反選">
65   <input type="button" id="btn5" value="獲得選中的所有值">
66   <br>
67   <input type="checkbox" name="checkbox" value="checkbox1">
68   checkbox1
69   <input type="checkbox" name="checkbox" value="checkbox2">
70   checkbox2
71   <input type="checkbox" name="checkbox" value="checkbox3">
72   checkbox3
73   <input type="checkbox" name="checkbox" value="checkbox4">
74   checkbox4
75   <input type="checkbox" name="checkbox" value="checkbox5">
76   checkbox5
77   <input type="checkbox" name="checkbox" value="checkbox6">
78   checkbox6
79   <input type="checkbox" name="checkbox" value="checkbox7">
80   checkbox7
81   <input type="checkbox" name="checkbox" value="checkbox8">
82 checkbox8
83 </form>
84
85 </BODY>
86</HTML>
87
 

 

2.

取select被選中option的value

$("#id").val();


取input的值

$("#id").attr("value");


寫這些,沒前途阿~

......


關於jquery常用方法的介紹:


http://www.jb51.net/article/20387.htm

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章