按下按钮时显示隐藏的div内容

时间:2013-09-11 11:11:17

标签: php jquery

你好吗?如何在按下按钮之前隐藏div内容?任何人都可以帮助我。我希望这个div不会出现,直到按下表格中的“添加新教师”按钮。这是div内容,我希望它在按下按钮之前隐藏

     <div id="myform">
<p align="center">
<strong>
Add information for new teacher here
</strong></p>
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
  <table align="center" id="forms">
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">First name:</td>
      <td><input type="text" name="first_name" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Last name:</td>
      <td><input type="text" name="last_name" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Subjects:</td>
      <td><input type="text" name="subjects" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Phonenumber:</td>
      <td><input type="text" name="phonenumber" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Email:</td>
      <td><input type="text" name="email" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Username:</td>
      <td><input type="text" name="username" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Password:</td>
      <td><input type="text" name="password" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">&nbsp;</td>
      <td><input type="submit" value="Insert record" id="hideit"/></td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="form1" />
</form>
<p>&nbsp;</p>
</div>

这是我的表格,其中包含“添加新教师”按钮

    <p align="center">
<strong>
List of teachers in Minaki Sec school
</strong></p>
<table border="1" align="center" class="altrowstable" id="alternatecolor">
  <tr id="row">
    <th>teacher id</th>
    <th>first name</th>
    <th>last name</th>
    <th>subjects</th>
    <th>Phonenumber</th>
    <th>Email</th>
    <th>username</th>
    <th>password</th>
    <th>Edit</th>
    <th>Delete</th>
    <th>Details</th>
  </tr>
  <?php do { ?>
    <tr>
      <td><?php echo $row_teacherrec['teacher_id']; ?></td>
      <td><?php echo $row_teacherrec['first_name']; ?></td>
      <td><?php echo $row_teacherrec['last_name']; ?></td>
      <td><?php echo $row_teacherrec['subjects']; ?></td>
      <td><?php echo $row_teacherrec['phonenumber']; ?></td>
      <td><?php echo $row_teacherrec['email']; ?></td>
      <td><?php echo $row_teacherrec['username']; ?></td>
      <td><?php echo $row_teacherrec['password']; ?></td>
      <td><button onclick="location.href= 'edit_teacher.php? teacher_id=<?php echo $row_teacherrec['teacher_id']; ?>'">Edit</button></td>
      <td><button onclick="location.href= 'delete_teacher.php? teacher_id=<?php echo $row_teacherrec['teacher_id']; ?>'">Delete</button></td>
      <td><button onclick="location.href= 'edit_teacher.php? teacher_id=<?php echo $row_teacherrec['teacher_id']; ?>'">Details</button></td>
    </tr>
    <?php } while ($row_teacherrec = mysql_fetch_assoc($teacherrec)); ?>
    <tr>
    <td colspan="8"></td>
    <td colspan="6" align="center"><button id="showit" onclick="location.href='teacher.php'">+Add new Teacher</button></td>
   </tr>
   </table>

6 个答案:

答案 0 :(得分:2)

试试吧,

$(function(){
   $('button#showit').on('click',function(){  
      $('#myform').show();
   });
});

最初 div应为hidden

<div id="myform" style="display:none">
.....

答案 1 :(得分:1)

为您的div添加display:none样式,然后在按钮点击时调用$("#div-id").show();

<div id="myform" style="display:none">
  // contents here
</div>

答案 2 :(得分:1)

在新教师表单上添加内联样式以隐藏表单

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

或在你的jQuery中添加

$(document).ready(function(){
    // hide form on page load
    $('#myform').hide();

    // when button is pressed
    $('button').on('click',function(){  
      $('#myform').show();
   });
});

答案 3 :(得分:0)

您可以使用jQuery 隐藏显示功能。

HERE

Show

Hide

答案 4 :(得分:0)

在您的代码中进行以下更改:

<div id="myform" style="display:none;">

在div中添加要隐藏的样式。

并将您的按钮代码修改为:

<button id="showit">+Add new Teacher</button>

并添加此jQuery:

$(document).ready(function(){
   $("#showit").click(function(){
       $("#myform").css("display","block");
   });
});

答案 5 :(得分:0)

$(function(){
    $('.button_name').click(function(){  
      $('#myform').show();
    });
 });





<button class="button_name">


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

或使用java脚本

function new_disp(){
   document.getElementById('myform').style.display='block';
 }




<button onclick='new_disp();'>


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