2012-01-13 20 views
0

我想将一个php变量传递给我的LinkONCLick4函数,但由于某种原因,该变量未被传递给conversation.php,该函数甚至无法工作。我早先在我的一个网页上使用了相同的功能,并且它运行良好;我不明白为什么现在不工作。我任何人都可以帮助我,这将是伟大的!将一个变量从php传递到javascript

<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> 

+0

尝试onclick =“LinkOnClick4(\'你好\')” – redmoon7777 2012-01-13 20:34:03

+0

'onclick =“LinkOnClick4(”你好“)”'显示了很多双引号...... – Grooveek 2012-01-13 20:34:13

+0

哦,废话的家伙,它肩d已经说过onclick =“LinkOnClick4('。$ users。'”) – Eggo 2012-01-13 20:35:06

回答

1

尝试用这种

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>'; 

除外替换您的生产线,一切都看起来不错,我无法找到任何东西,可能是导致问题的原因

+0

您好,先生,您真棒。非常感谢帮忙。我昨晚花了两个小时试图解决的解决方案在这里5分钟内得到修复。对此,我真的非常感激! – Eggo 2012-01-13 20:39:42

+0

@Eggo - 完全没问题:)很高兴帮助!请点击我问题旁边的“打勾”,让其他人知道问题已经解决:) – Tom 2012-01-13 20:41:06

+0

我知道,但我说我不能再点击它四分钟。 – Eggo 2012-01-13 20:41:46