1
下面你会发现我的代码用于从表格中提取数据以及我想用最后一个按钮标签中列出的每个表格行重复的图像Class = plusbtn重复元素的onclick事件只适用于第一行
{
$event .= ' <div style="border-bottom:1px solid gray;padding:2px;width:100%;float:left;"><div id="eventslist" onclick="goevent('.$row['id'].');">
<div style="width:100%;float:left;">
<h4 style="margin:0;"><span id="eventuser" style="width:50%;float:left;text-align:left;font-size:14px;"><img src="https:///login/profile/'.$row['profile_img1'].'" style="width:35px;height:37px;border-radius:20px;margin-left:-4%;background:url(http:///img/person-placeholder.jpg) no-repeat center" class="img-rounded"> <b>'.$row['user'].'</b></span><span style="float:right;text-align:right;font-size:12px;margin-top:9px;margin-right:-25px;">Posted: '.$row['stdate'].' </span><br/><br/><b><span style="font-size:20px;float:left;">'.$row['fname'].' </span></b></h4>
</div>
<div style="width:109%;float:left;">
<img src="http:///login/image/'.$row['name'].'" style="width:100%;height:35%;border-radius:10px;margin-left:-4%;background:url(https:///img/load.gif) no-repeat white" class="img-rounded">
</div>
<div style="width:100%;float:left;">
<p style="margin-bottom:0;">'.substr($row['description'],0,110).'...</p>
</div>
</div><div><button class="plusbtn" onclick="plusrate(\''.$likecount.'\');"><a onclick="document.getElementById(`myImage`).src=`https:///img/fav4.png`"><img id="myImage" src="https:///img/fav3.png" style="opacity: 0.7;height:25px;max-width:100px"></a></button><span id="likeqnty" class="likeqnty">0</span> <b>Likes</b></div></div> ';
}
使用该设置按钮图像出现的每个条目,但我只能点击按钮在我的网页上的第一项。当我在页面上出现按钮(回声“按钮”)时输入回显
如何使每个表格条目重复一次,并正确地将fav4转换为fav3。
由于点击时img/fav4切换到img/fav3,所以ID相同。这是一个像按钮,第一个图像是一个开放的心,第二个图像被点击时是一个填充的心脏 – Answerme
我认为你在混合ID和SRC ... SRC是图片SouRCe,而ID只是一个标识符html元素。 – Salketer