[英]Why cant my <a href link work?
當我單擊鏈接時,它無法工作。
這些是我的代碼:
if (mysql_num_rows($sql1)) {
echo"<table>";
while ($row1 = mysql_fetch_array($sql1)) {
if($row1['topic_id'] == $row['topic_id']){
echo "<tr><th><font color='blue'>".$row1['topic_name']."</th></tr> </font>";
echo"<a href='postreply.php?cat_id='$cat_id'&topic_id='$topic_id'&topic_creator='$topic_creator''>hi</a>";
}
}
echo "<tr><td>".$row['post_content']."</td></tr>";
echo"</table><hr>";
}
您的引號破壞了代碼,您將需要轉義雙引號,因此它們不會被視為PHP代碼。 您可以通過在它們前面鍵入\\
字符來實現。
在上面的代碼中,進行如下修改:
echo"<a href='postreply.php?cat_id='$cat_id'&topic_id=\"$topic_id'&topic_creator=\"$topic_creator''>hi</a>";
多重'
不需要之間的空間?
cat
也可能引起問題
echo"<a href='postreply.php?cat_id=$cat_id&topic_id=$topic_id&topic_creator=$topic_creator'>hi</a>";
試試看,
echo"<a href='postreply.php?cat_id=$cat_id&topic_id=$topic_id&topic_creator=$topic_creator'>hi</a>";
您的代碼由於href屬性中'的錯誤使用而中斷
編輯:
您仍無法單擊該元素,因為父元素#notificationContainer click事件偵聽器的返回false也會阻止子元素的默認操作。
您可以通過更改該代碼的偵聽器代碼或停止從子項a到父項#notificationContainer的事件傳播來使鏈接正常工作。 這將停止調用父click事件偵聽器,並允許a元素的默認操作。
所以要么刪除
$("#notificationContainer").click(function()
{
return false;
});
或添加以下代碼以阻止腳本中的傳播。
$("#notificationContainer a").click(function(e)
{
e.stopPropagation();
});
不要在php echo "<h1>Don't Use This</h1>";
內部使用HTML
標簽php echo "<h1>Don't Use This</h1>";
因為當您在較大的項目中使用這些代碼時,可能會產生縮進的問題,省略“分號等”。請嘗試使代碼保持良好的格式。
另一方面,我建議您使用phpi類和對象,即帶有預准備語句的mysqli對象。這些將有助於更好的編碼方式。
<?php
if (mysql_num_rows($sql1)){
?>
<table>
<?php
while ($row1 = mysql_fetch_array($sql1)) {
if($row1['topic_id'] == $row['topic_id']){
?>
<tr>
<th><font color='blue'><?php echo $row1['topic_name'];?></font></th>
</tr>
<a href="postreply.php?cat_id=<?php echo "cat_id=".$cat_id."&topic_id=".$topic_id."&topic_creator=".$topic_creator;?>">hi</a>
<?php
}
}
?>
<tr>
<td><?php echo $row['post_content'];?></td>
</tr>
</table>
<hr>
<?php
}
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.