dqn8235 2014-04-24 09:20
浏览 41
已采纳

按链接显示/隐藏<div>

I want to show a element when I click a link. All links are questions and all the contains answers for each question . Both question and answer are taken from database so I want to have their id.

The problem is that when I click the link it doesn't work and nothing happens.

The code is this:

<?php 

$req= 'SELECT * from plot q, curse c where q.id_quest='.$data['id_q'].' and q.id_curs=c.id_cursus';
$result=mysql_query($req) or die('Erreur SQL !<br>'.$sql2.'<br>'.mysql_error()); 

$currentid=$data['id_q'];
$test='test';
$currentrep=$currentid.$test;


echo  '<a id='.$currentid.' href="javascript:toggle('.$currentid.','.$currentrep.');"><b>    <h8> Question : </b> '.$data['int_question'].'</h8><br></a>';

echo '<div  id='.$currentrep.' style="display: none"><b>Réponse </b> : '.$data['rep'].'<nbsp>';

?>
  • 写回答

1条回答 默认 最新

  • dov6891 2014-04-24 09:30
    关注

    You have to escape quotations correctly to pass strings to the JS function:

    echo  '<a id="'.$currentid.'" href="javascript:toggle(\''.$currentid.'\', \''.$currentrep.'\');"><b>    <h8> Question : </b> '.$data['int_question'].'</h8><br></a>';
    
    echo '<div id="'.$currentrep.'" style="display: none"><b>Réponse </b> : '.$data['rep'].'<nbsp>';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错