【问题标题】:Show and hide content from a vanity url显示和隐藏虚 url 的内容
【发布时间】:2014-06-10 15:49:28
【问题描述】:

好的,我有一个 php 和 mysql 的博客。我想用显示和隐藏 javascript 函数在 div 中打开 url。与其他 div 一起工作正常,但问题是当我点击虚荣 url 时,我的网站总是会更新。我有一个格式化这个 url 的函数,我不能从这个 url 编辑 html。 我想在与博客相同的 div 上打开此 url 的内容,而不更新索引页面。我该如何实施?这是我的代码:

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>

            <? 
         }
    } ?>

我的javascript函数:

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

【问题讨论】:

标签: javascript php jquery html vanity-url


【解决方案1】:

在“a”标签上写js函数最好使用这种方法。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-08
    • 1970-01-01
    • 1970-01-01
    • 2013-11-06
    相关资源
    最近更新 更多