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>';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)