通过链接显示/隐藏<div> </div>

时间:2014-04-24 09:20:38

标签: javascript php html

我想在点击链接时显示一个元素。所有链接都是问题,所有内容都包含每个问题的答案。问题和答案都来自数据库,所以我想得到他们的身份。

问题在于,当我点击链接时,它不起作用,没有任何反应。

代码是这样的:

<?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 个答案:

答案 0 :(得分:1)

您必须正确地转义引号才能将字符串传递给JS函数:

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>';
相关问题