jquery一些简单的小技巧

1 checkbox反选

   

<input type= button value="反选" id="aa" onclick="check()">

<hr>

<input type=checkbox class="chk"> <br>

<input type=checkbox class="chk"> <br>

<input type=checkbox class="chk"> <br>

<input type=checkbox class="chk"> <br>

<input type=checkbox class="chk"> <br>

<input type=checkbox class="chk"> <br>



<script>

  function check(status)

  {

     //这里的obj是dom

     $(".chk").each(

	 

	      function(i,obj){

	             obj.checked=!obj.checked;

	 

	       }  

	 

	 );

  }

</script>
2  复选框至少选一个


<input type= button value="删除" id="aa" onclick="check()">

<hr>

<input type=checkbox class="chk"> <br>

<input type=checkbox class="chk"> <br>

<input type=checkbox class="chk"> <br>

<input type=checkbox class="chk"> <br>

<input type=checkbox class="chk"> <br>

<input type=checkbox class="chk"> <br>



<script>

  function check(status)

  {

     if ($(".chk:checked").size()<1)

     {

	   alert("请选中先");

	   return;

     }

  }

</script>

3  checkbox全选和全不选


<input type= button value="反选" id="aa" onclick="check()">

<hr>

<input type=checkbox class="chk"> <br>

<input type=checkbox class="chk"> <br>

<input type=checkbox class="chk"> <br>

<input type=checkbox class="chk"> <br>

<input type=checkbox class="chk"> <br>

<input type=checkbox class="chk"> <br>



<script>

  function check(status)

  {

     //这里的obj是dom

     $(".chk").each(

	 

	      function(i,obj){

	             obj.checked=!obj.checked;

	 

	       }  

	 

	 );

  }

</script>
4 multiple select列表传值


<select multiple id="left">

  <option value="九阴真经">九阴真经</option>

  <option value="九阴真经">九阳神功</option>

  <option value="九阴真经">一阳指</option>

  <option value="九阴真经">玉女心经</option>

</select>

    

   <input type=button value=">" onclick="left2right()">

<select id="right" multiple>

</select>





<script>

    function left2right()

	{

       $("#left>option:selected").remove().appendTo($("#right"));

	}

</script>


你可能感兴趣的:(jquery一些简单的小技巧)