我想添加一個只對Admin可見的刪除按鈕。但同時,第一行將爲用戶提供「我已閱讀此信息」按鈕。在此代碼上,刪除按鈕不能隱藏所有行。刪除按鈕只能隱藏第一行。如果用戶不是管理員,我希望刪除按鈕不會出現在任何地方。只操作foreach循環的第一行並同時處理所有行
我試過這個JavaScript代碼,但它隻影響我的foreach循環的第一行。我不知道該怎麼做。你有什麼主意嗎?
<?php if(($_SESSION['username'] == 'Admin')) {
echo "<script> $('#del_photo').hide(); </script> ";
}
foreach($select as $index => $rs) {
?>
<div class="post-id" id="<?php echo $rs['id']; ?>" style="margin 300px; overflow: hidden; border-top-right-radius: 25px; border-top-left-radius: 25px; display:block;
position: relative; margin: 20px; border: 2px solid #222;">
<br><br>
<h2 class="blog-post-title"><?php echo $rs['title'];?></h2>
<p class="blog-post-meta"> <?php echo $rs['date'];?> skrevs av <a href="#"> <?php echo $rs['author'];?></a></p>
<?php
$i = 0;
$len = count($select);
foreach ($select as $item) {
if ($i == 0) {
echo "<form action=\"#\" style=\" height:30px; background:transparent; border:none; color:transparent;\" method=\"get\"> <button name=\"readit\" id=\"readit\"
style=\" height:30px; position:absolute; background:transparent; border:none; color:transparent; width:70px; display: flex; top:-0.5%; left:0%; float:right; margin:5px 5px 0 0;\"
class=\"del_photo\"> <span src=\"sett.png\" class=\"readit\" id=\"readit\" ></span><img src=\"sett.png\" class=\"readit\" border=\"0\" /></button> </form>";
} else if ($i == $len - 1) {
echo "// last";
}
$i++;
}
?>
<br>
<center><p style="margin-left:auto; margin-right: auto; display:block; height: 100%; max-width: 100%; margin-bottom:0px;"><?php echo $rs['content'];?></p></center></br>
<img style=" margin-left:auto; margin-right: auto; display:block; height: 100%; max-width: 100%; margin-bottom:0px;" src='<?php echo $rs['image'];?>' width="400" height="300">
<button id="del_photo" style=" background:transparent; border:none; width:350px; height: 250px; color:transparent; display: inline-block;
float:right; margin:5px 5px 0 0; position: absolute; top: 0; right: 0;"
class="del_photo" onclick="deletepost('<?php echo $rs['id']; ?>')"> <span class="del_photo" id="del_photo" src="x.png" style=" display: inline-block;
float:right; margin:5px 5px 0 0; position: absolute; top: 0; right: 0;"
id="" ></span><img class="del_photo" id="del_photo" src="x.png" style=" display: inline-block;
float:right; margin:5px 5px 0 0; position: absolute; top: 0; right: 0;" class="del_photo" border="0" /></button>
</div>
<?php
}
?>
這似乎LIK e您的代碼不在循環中 – henrily
循環完美無缺。我可以在瀏覽器上看到它。但我想通過隱藏按鈕來影響所有行。我想爲特定的會話呼叫隱藏它。 –
因爲我不是很確定,而是把'id =「del_photo」'改成'class =「del_photo」'這樣的類名,並把javascript'#del_photo'改成'.del_photo' ID到類)元素ID是唯一的,因此應該只出現一次。 –