简体   繁体   English

显示和隐藏虚荣网址中的内容

[英]Show and hide content from a vanity url

Ok I have a blog in php and mysql. 好的我有一个php和mysql的博客。 I want to open the url in a div with show and hide javascript functions. 我想在显示和隐藏javascript函数的div中打开url。 Works fine with the rest of divs but the problem is when I click on a vanity url my web is always updated. 与其他div一起工作正常,但问题是当我点击虚荣网址时,我的网页总是更新。 I have a function that format this urls and i can't edit the html from this urls. 我有一个格式化这个网址的功能,我无法从这个网址编辑html。 I want open the content of this url on the same div that blog is it without updating the index page. 我希望在不更新索引页面的情况下在博客相同的div上打开此URL的内容。 How can I implement this? 我该如何实现呢? Here my code: 这是我的代码:

blog.php blog.php的

<?php
if($_GET['id']) {

$sql = "select * from blog where id = '".$_GET['id']."' ";
$consulta = mysql_query($sql);
if (mysql_num_rows($consulta)!=0) {
    $fila=mysql_fetch_assoc($consulta);
    $fecha = date("d.m.Y", strtotime($fila['fecha']));

  echo $fila["nombre"]; 

 } 
} else {

  $sql = "select * from blog where estado = 1 order by fecha desc ";

  $consulta = mysql_query($sql);
        while ($fila=mysql_fetch_assoc($consulta)) { 

            $fecha = date("d.m.Y", strtotime($fila['fecha']));
            $url = "blog/".formato($fila["nombre"])."-".$fila["id"].".html";
            ?>

            <a id="enlace" href="<? echo $url; ?>"><?php echo $fila["nombre"]; ?></a>

            <? 
         }
    } ?>

My javascript function: 我的javascript函数:

 <script type="text/javascript">
$(document).ready(function(){
    $("#enlace").click(function(){
        $('#blog').hide(); //muestro mediante id
        $('#content_blog').show(); //muestro mediante clase
     });
});

for writing js Function on "a" tag better is use this method. 用于编写js函数对“a”标记更好是使用此方法。

 $('body').on("click","a#enlace", function(e){
   e.preventDefault();
     ....your codes ...
 });

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

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