que"/> que">

Home  >  Article  >  Backend Development  >  关于回复功能解决办法

关于回复功能解决办法

WBOY
WBOYOriginal
2016-06-13 12:16:41836browse

关于回复功能
数据库读取出的回复内容:

$sql="select * from massage where iid=$iid order by mid desc limit $offset,$pagesize";<br />$result=$db->query($sql);<br />while (($row=$result->fetch_assoc())!=false) {<br />	<br />	 echo  '<div id="msg"><br />	           <table width="800" height="auto" border="0" cellpadding="0" cellspacing="0" align="center" bgcolor="#FFFFFF"><br />                    <tr><br />                       <th scope="row" width="100" align="center"><strong id="mid">#'.$row["mid"].'</strong><br /><a href="data.php">'.$row["author"].'</a></th><br />                       <td><p id="msgten">'.$row["msg"].'</p><span><a href="#msgcon" onclick="toCopy();">回复</a>'.$row["time"].'</span></td><br />                    </tr><br />               </table><br />			</div>';<br />}


将上面读出来的内容复制到textarea里 :
<script><br />	 function toCopy(){<br />		 var midval= document.getElementById("mid").innerHTML;<br />		 var msg= document.getElementById("msgten").innerHTML;<br />         document.getElementById("msgcon").value = "回复"+midval+"楼"+"["+msg+"]";<br />         document.getElementById("msgcon").focus();<br />	 }<br /></script>


效果:


问题是 :文本框里显示的永远是数据库读出来的最后一条,也就是第13条,如何做到点哪个回复就把那条复制到框里
------解决思路----------------------
id="msgten"

你的id重复了,不能这样用的。
修改为这样看看
<br />$sql="select * from massage where iid=$iid order by mid desc limit $offset,$pagesize";<br />$result=$db->query($sql);<br />$i = 0;<br />while (($row=$result->fetch_assoc())!=false) {<br />     <br />     echo  '<div id="msg'.$i.'"><br />               <table width="800" height="auto" border="0" cellpadding="0" cellspacing="0" align="center" bgcolor="#FFFFFF"><br />                    <tr><br />                       <th scope="row" width="100" align="center"><strong id="mid'.$i.'">#'.$row["mid"].'</strong><br /><a href="data.php">'.$row["author"].'</a></th><br />                       <td><p id="msgten'.$i.'">'.$row["msg"].'</p><span><a href="#msgcon" onclick="toCopy('.$i.');">回复</a>'.$row["time"].'</span></td><br />                    </tr><br />               </table><br />            </div>';<br /><br />    $i++;<br />}<br />


<br /><script><br />     function toCopy(c){<br />         var midval= document.getElementById("mid"+c).innerHTML;<br />         var msg= document.getElementById("msgten"+c).innerHTML;<br />         document.getElementById("msgcon").value = "回复"+midval+"楼"+"["+msg+"]";<br />         document.getElementById("msgcon").focus();<br />     }<br /></script><br />

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn