将变量从php传递到javascript
我试图将一个php变量传递给我的LinkONCLick4函数,但由于某种原因,该变量没有传递给conversation.php,该函数甚至无法工作。我之前在我的一个网页上使用了同样的功能,效果很好;我不知道为什么它现在不起作用。我希望任何人都能帮助我,那太好了将变量从php传递到javascript,php,javascript,Php,Javascript,我试图将一个php变量传递给我的LinkONCLick4函数,但由于某种原因,该变量没有传递给conversation.php,该函数甚至无法工作。我之前在我的一个网页上使用了同样的功能,效果很好;我不知道为什么它现在不起作用。我希望任何人都能帮助我,那太好了 <script> function LinkOnClick4(box) { $('#friendresults').load('conversation.php?id=' + box); } &
<script>
function LinkOnClick4(box) {
$('#friendresults').load('conversation.php?id=' + box);
}
</script>
<div id='showfriends' style='display:none;'>
<div style="margin-top:5px;"><input type='text' name='searchfriends' id='searchfriends' class='searchfriends' autocomplete="off" value="Search for a friend..." onClick="this.style.border = '1px solid #4F94CD'; document.getElementById('friendresults').style.visibility = 'visible';" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue; this.style.border = '1px solid #5E5E5E';" onkeyup='searchfriends()'/></div>
<div id='hrdiv3'></div>
<div id='friendresults' name='friendresults' style='float:left;'>
<?php
$construct = "SELECT * FROM acceptedfriends WHERE profilename='$profilename' ORDER BY id DESC LIMIT 6";
$run = mysql_query($construct);
$foundnum = mysql_num_rows($run);
while ($runrows = mysql_fetch_assoc($run))
{
$users = $runrows['username'];
$location = $runrows['imagelocation'];
$image = "<img src='$location' style='width:60px; height:40px;' />";
if ($profilename==$username)
{
echo '<div id="hovercolor2" onclick="LinkOnClick4('.$users.')" style="width:294px; float:left;"><table><tr><td>'.$image.'</td><td><div style="margin-bottom:5px;"><a href="http://www.pearlsquirrel.com/'.$users.'" target="_blank">'.$users.'</a></div><div><a href="http://www.pearlsquirrel.com/conversation.php/'.$pageusers.'" style="text-decoration:underline;" target="_blank"><div style="font-size:.7em";>Click to enter a conversation.</div></a></div></td></tr></table></div><div id="hrdiv3" style="float:left; width:298px;"></div>';
}
else
{
echo '<div id="hovercolor2" style="width:294px; float:left;"><table><tr><td>'.$image.'</td><td><a href="http://www.pearlsquirrel.com/'.$users.'" target="_blank">'.$users.'</a></td></tr></table></div><div id="hrdiv3" style="float:left; width:298px;"></div>';
}
}
?>
</div>
</div>
</div>
</div>
</div>
功能链接单击4(框){
$('#friendresults').load('conversation.php?id='+box);
}
试着用这个替换你的线路
echo '<div id="hovercolor2" onclick="LinkOnClick4(\'' . $users . '\')" style="width:294px; float:left;"><table><tr><td>'.$image.'</td><td><div style="margin-bottom:5px;"><a href="http://www.pearlsquirrel.com/'.$users.'" target="_blank">'.$users.'</a></div><div><a href="http://www.pearlsquirrel.com/conversation.php/'.$pageusers.'" style="text-decoration:underline;" target="_blank"><div style="font-size:.7em";>Click to enter a conversation.</div></a></div></td></tr></table></div><div id="hrdiv3" style="float:left; width:298px;"></div>';
echo'.$image';
除此之外,一切看起来都很好,我找不到任何其他可能导致问题的原因试试onclick=“LinkOnClick4(\'hello\”)“onclick=“LinkOnClick4”('hello”)”
显示了很多双引号……噢,废话,应该是onclick=“LinkOnClick4('.$users.””它对变量的作用和对普通文本的作用一样吗?@Eggo-检查下面我的答案你我的好先生真了不起。非常感谢你的帮助。昨晚我花了两个小时试图解决的问题在这里用了5分钟就解决了。我真的很感激@Eggo-没问题:)很乐意帮忙!请点击我的问题旁边的“勾号”,让其他人知道问题已经解决:)我知道,但我说我不能再点击它四分钟。