简体   繁体   English

用php显示div元素的JQuery

[英]JQuery with php showing div element

The problem is when I press left-nav "a" element it should show() me the div element, but its going to hide() it automatically. 问题是当我按下left-nav“a”元素时它应该show()我div元素,但它会自动hide()它。 The "a" element is created with php and it has href of ?id=$product , when I press class closebtn "a" element in side my navbar it show() 's me the div. “a”元素是用php创建的,它的href为?id=$product ,当我在类closebtn按下类closebtn “a”元素时,它show()是我的div。

JavaScript: JavaScript的:

$(document).ready( function() {
    $(".sisu").hide();
    $('.vasaknav a').click( function() {
        $(".sisu").show();
    });
});

PHP: PHP:

<?php
    $kask=$yhendus->prepare("SELECT id,Product from store GROUP BY Product");
    $kask->bind_result($id, $Product);
    $kask->execute();

    while($kask->fetch()){
        echo "<a href='?id=$Product' style='color:red;'>".htmlspecialchars($Product)."</a>";
    }
?>

HTML: HTML:

<div id="Myvasaknav" class="vasaknav">
    <a href="javascript:void(0)" class="closebtn" onclick="closeNav()">&times;</a>
    <?php require('php/navlist.php'); ?>
    <a href=#  >test</a>
</div>

<span style="font-size:30px;cursor:pointer" onclick="openNav()" id="click">&#9776;</span>

To prevent default action when clicking <a> (which is reloading page / redirecting elsewhere) you should change your code like: 要在单击<a> (重新加载页面/重定向到其他位置)时阻止默认操作,您应该更改以下代码:

$(document).ready( function() {
    $(".sisu").hide();
    $('.vasaknav a').click( function() {
        $(".sisu").show();
        return false;   // prevent default action
    });
});

With this you will stay on the same page and .sisu element will be shown. 有了这个,你将保持在同一页面上,并显示.sisu元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM