2014-02-14 47 views
0

我在調用PHP文件的html頁面中有按鈕單擊事件。在PHP內我有兩個div,我想顯示隱藏根據複選框我有... 現在它顯示兩個複選框和顯示div。但我想加載顯示div只有當用戶檢查第一個複選框我怎麼能做到這一點?請幫助。這裏的PHP代碼div在複選框中隱藏和顯示PHP內部

<div id="dialog_title"> 
    <input type="checkbox" name="First" value="First"> 
    First List<br> 
     <input type="checkbox" name="Second" value="Second">Second 
</div> 

    <div id="Show div"> 

     <table> 
      <tr> 
       <th> Name </th> 
       <th> Address </th> 
      </tr> 
      <?php 
      foreach ($deviceArr as $device) { 
       $id = $device['id']; 
       $name = $device ['name']; 
       $Address = $device['address']; 
       ?> 
       <tr class="font1"> 
        <td> <input type="text" class="g_input_text" name="name[]" value="<?php echo $name; ?>" /> </td> 
        <td> 
         <input type="text" class="g_input_text" name="address[]" value="<?php echo $Address; ?>" /> 
         <input type="hidden" name="id[]" value="<?php echo $id; ?>" /> 
        </td> 
       </tr> 
       <?php 
      } 
      ?> 


     </table> 

    </div> 
+1

你是如何調用PHP文件與表單發佈或JavaScript? –

回答

1

這是你的期望?

$(document).ready(function() { 
    $('#Show').hide(); 
    $("input[name=First]").click(function() { 
     $('#Show').toggle(); 
    }); 
}); 

它在JQuery完成。查找Demo

注:更改<div id="Show div"><div id="Show">

+0

+1適用於演示。很簡單的答案 –

2

當頁面加載隱藏的show div我命名爲first_list_bx並給出一個ID爲first_chk_bx到第一個複選框,如:

<input type="checkbox" name="First" value="First" id="first_chk_bx"> 

<div id="first_list_bx" style="display:none;"> 
    //code 
</div> 

然後使用jquery用於檢測checkbox的複選框並顯示如下first_list_bx

$('#first_chk_bx').click(function() { 
    if($(this).is(":checked")){ 
     $("#first_list_bx").show(); 
    } 
    else{ 
     $("#first_list_bx").hide(); 
    } 
}); 
0

爲您javascript標記你的問題試試這個js函數在HTML這樣

HTML

<div id="dialog_title"> 
    <input type="checkbox" name="First" value="First" onclick="javascript:show_hide(this, 'Show_div')"> 
    First List<br> 
     <input type="checkbox" name="Second" value="Second">Second 
</div> 

    <div id="Show_div" style="display:none"> 

     <table> 
      <tr> 
       <th> Name </th> 
       <th> Address </th> 
      </tr> 

       <?php 
     foreach ($deviceArr as $device) { 
      $id = $device['id']; 
      $name = $device ['name']; 
      $Address = $device['address']; 
      ?> 
      <tr class="font1"> 
       <td> <input type="text" class="g_input_text" name="name[]" value="<?php echo $name; ?>" /> </td> 
       <td> 
        <input type="text" class="g_input_text" name="address[]" value="<?php echo $Address; ?>" /> 
        <input type="hidden" name="id[]" value="<?php echo $id; ?>" /> 
       </td> 
      </tr> 
      <?php 
     } 
     ?> 




     </table> 

    </div> 

JAVASCRIPT

<script> 
     function show_hide(my_obj, id) 
     { 
      var chk = my_obj.checked; 
      if(chk===true) 
      { 
       document.getElementById(id).style.display="block"; 
      } 
      else 
      { 
       document.getElementById(id).style.display="none"; 
      } 
     } 
    </script>