본문 바로가기
컴퓨터이야기/JQuery

전체 선택

by 변화지시자 2013. 5. 2.
반응형

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <title> New Document </title>
  <meta name="Generator" content="EditPlus">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
      <script src="http://code.jquery.com/jquery-1.9.1.js"></script>

 </head>

 <body>

 <table id='contentsTable'  class='grid' width='100%' border="1">
                                        <thead>
                                            <tr>
                                              <th width='10%' ><input type='button' id='btn_all' value='selall' /></th>
                                              <th width='70%'>aaa</th>
                                            </tr>
                                        </thead>
                                        <tbody>

      
              <tr>
                   <td width='10%' rowspan='2' align='center'><input type='checkbox' name='chkBox' id='chkBox' /></td>
                   <td  align='center'><input type='text' name='textfield2' id='textfield2' value='xTitle' /></td>
                    </tr>
                 <tr>
                   <td  align='center'><textarea name='textarea' id='textarea' cols='45' rows='5'>xConts</textarea></td>
                    </tr>
              <tr>
                   <td width='10%' rowspan='2' align='center'><div id="divid"><input type='checkbox' name='chkBox' id='chkBox' /></div></td>
                   <td  align='center'><input type='text' name='textfield2' id='textfield2' value='xTitle' /></td>
                    </tr>
                 <tr>
                   <td  align='center'><textarea name='textarea' id='textarea' cols='45' rows='5'>xConts</textarea></td>
                    </tr>
                       
                                 </tbody>
                                     </table>
 </body>
</html>
<script type="text/javascript">
<!--
/*
 var flip = 0;
 $('#btn_all').bind({
   click:function(){
     if(flip % 2 ==0){
      jQuery("input[name=chkBox]").prop("checked",true)
     }else{
      jQuery("input[name=chkBox]").prop("checked",false)
     }
     flip++;
     alert(flip);
    }
 });
*/

 var flip = 0;
 $('#btn_all').click(function(){
     if(flip % 2 ==0){
      jQuery("input[name=chkBox]").prop("checked",true)
     }else{
      jQuery("input[name=chkBox]").prop("checked",false)
     }
     flip++;
     alert(flip);
   
 });
//-->
</script>

 

 

 

 

 

selectall.html




 




//jquery API

--------------------- -----------------------------------

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

 <head>

  <title> New Document </title>

  <meta name="Generator" content="EditPlus">

  <meta name="Author" content="">

  <meta name="Keywords" content="">

  <meta name="Description" content="">

      <script src="http://code.jquery.com/jquery-1.9.1.js"></script>


 </head>


 <body>


 <table id='contentsTable'  class='grid' width='100%' border="1">

                                        <thead>

                                            <tr>

                                              <th width='10%' ><input type='button' id='btn_all' value='selall' /></th>

                                              <th width='70%'>aaa</th>

                                            </tr>

                                        </thead>

                                        <tbody>


       

      <tr>

         <td width='10%' rowspan='2' align='center'><input type='checkbox' name='chkBox' id='chkBox' /></td>

         <td  align='center'><input type='text' name='textfield2' id='textfield2' value='xTitle' /></td>

           </tr>

       <tr>

         <td  align='center'><textarea name='textarea' id='textarea' cols='45' rows='5'>xConts</textarea></td>

           </tr>

      <tr>

         <td width='10%' rowspan='2' align='center'><div id="divid"><input type='checkbox' name='chkBox' id='chkBox' /></div></td>

         <td  align='center'><input type='text' name='textfield2' id='textfield2' value='xTitle' /></td>

           </tr>

       <tr>

         <td  align='center'><textarea name='textarea' id='textarea' cols='45' rows='5'>xConts</textarea></td>

           </tr>

                        

                                 </tbody>

                                     </table>

 </body>

</html>

<script type="text/javascript">

<!--



$('#btn_all').click(function(){

$("input[type='checkbox']").prop("checked", function( i, val ) {

alert(i);

return !val;

});



//-->

</script>