2016-07-09 16 views
0

Ich möchte eine versteckte div zeigen, wenn ich Maus über einen Link auf meiner Tabellenzelle. Das Ereignis wird nur in der ersten Zeile ausgelöst. Das ist, was ich tat:Jquery Maus über Ereignis

$(document).ready(function(){ 
    $("#show_div").mouseover(function() { 
     $("#hello").css('visibility', 'visible'); 
    }); 
    $("#hello").mouseover(function() { 
     $("#hello").css('visibility', 'visible'); 
    }); 
    $("#hello").mouseout(function() { 
     $("#hello").css('visibility', 'hidden'); 
    }); 
}); 
<form action="" method="post"> 
    <table class="table table-bordered table-hover"> 
     <div id="bulkOptionContainer" class="col-xs-4"> 
      <select class="form-control" name="bulk_options" id=""> 
       <option value="">Select Option</option> 
       <option value="publish">Publish</option> 
       <option value="draft">Draft</option> 
       <option value="delete">Delete</option> 
      </select> 
     </div> 
     <div class="col-xs-4"> 
      <input class="btn btn-success" type="submit" name="submit" value="Apply"/> 
      <a class="btn btn-primary" href="posts.php?source=add_post">Add New</a> 
     </div> 
     <thead> 
     <tr> 
      <th><input type="checkbox" name="checkbox[]" id="selectAllCheckBoxes"></th> 
      <th>Id</th> 
      <th>Author</th> 
      <th scope="col">Title</th> 
      <th>Category</th> 
      <th>Status</th> 
      <th>Image</th> 
      <th>Tags</th> 
      <th>Comments</th> 
      <th>Date</th> 
      <th>Edit</th> 
      <th>Delete</th> 
     </tr> 
     </thead> 
     <tbody> 
     <?php $query = "SELECT * FROM post ORDER BY post_id DESC"; 
     $result_set = mysqli_query($link, $query); 
     confirm_query($result_set); 
     while ($row = mysqli_fetch_assoc($result_set)):?> 

      <tr> 
       <td><label><input type="checkbox" class="checkBoxes" name="checkBoxArray[]" 
            value="<?php echo $row['post_id']; ?>"></label></td> 
       <td><?php echo $row['post_id'] ?></td> 
       <td><?php echo $row['post_author'] ?></td> 
       <td width="100%"> 

        <!-- link to over--> 
        <a id="show_div" 
         href="../post.php?p_id=<?php echo $row['post_id'] ?>"><?php echo $row['post_title'] ?></a> 
        <!-- div to become visible on hover--> 
        <div id="hello" style="visibility:hidden;"> 
         <p>post</p> 
        </div> 
       </td> 
       <td><?php echo sel_cat_byId($row['post_category_id']) ?></td> 
       <td><?php echo $row['post_status'] ?></td> 
       <td><img width="100" class="img-responsive" src="../images/<?php echo $row['post_image'] ?>"></td> 
       <td><?php echo $row['post_tag'] ?></td> 
       <td><?php echo $row['post_comment_count']; ?></td> 
       <td><?php echo $row['post_date'] ?></td> 
       <td><a class="btn btn-danger" href="posts.php?delete=<?php echo $row['post_id']; ?> " 
         onclick="alert('Are You Sure?')">Delete</a></td> 
       </td> 
       <td><a class="btn btn-success" href="posts.php?source=edit_post&edit=<?php echo $row['post_id']; ?>">Edit</a> 
       </td> 
       </td> 

      </tr> 



     <?php endwhile; ?> 

     </tbody> 
    </table> 
</form> 

**** das Ereignis nur feuert auf der ersten Reihe. Dank

+2

Verwenden Klasse statt ID. IDs sollten eindeutig sein –

+0

Bitte fügen Sie eine [mcve] in Ihre Frage ein. Das ist: Dies ist ein Problem mit Ihrer jQuery, also veröffentlichen Sie den relevanten Teil des generierten HTML. Noch besser: Kochen Sie den HTML-Code auf das Notwendigste, um das Problem zu reproduzieren. Das würde es viel einfacher für Sie machen zu sehen, was mit dem Code auch falsch ist. – Sumurai8

+1

Sie haben ein paar Probleme - zuerst Ihre PHP-Schleife wird viele Elemente mit der gleichen 'ID' erstellen, die ungültig ist, da sie eindeutig sein sollten. Zweitens ist Ihr HTML ungültig, da ein "div" -Element kein Kind einer 'Tabelle' sein kann. –

Antwort

2

zuerst Ihre ID mit Klasse ersetzen und dann versuchen, diese

$(".show_div").mouseover(function() { 
 
     $(this).next(".hello").css('visibility', 'visible'); 
 
    }); 
 
    $(".show_div").mouseout(function() { 
 
     $(this).next(".hello").css('visibility', 'hidden'); 
 
    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script> 
 
<a class="show_div" 
 
         href="#">abc</a> 
 
        <!-- div to become visible on hover--> 
 
        <div class="hello" style="visibility:hidden;"> 
 
         <p>post</p> 
 
        </div>

+0

Thankkks, funktioniert die nächste() wie eine Schleife? – bgreatfit

+0

es ist das nächste Element auswählen. Wie hier ist es das nächste Element, dessen Klasse "Hallo" ist. – ankit

Verwandte Themen