关于回复功能
数据库读取出的回复内容:
$sql="select * from massage where iid=$iid order by mid desc limit $offset,$pagesize";$result=$db->query($sql);while (($row=$result->fetch_assoc())!=false) { echo '<div id="msg"> <table width="800" height="auto" border="0" cellpadding="0" cellspacing="0" align="center" bgcolor="#FFFFFF"> <tr> <th scope="row" width="100" align="center"><strong id="mid">#'.$row["mid"].'</strong><br /><a href="data.php">'.$row["author"].'</a></th> <td><p id="msgten">'.$row["msg"].'</p><span><a href="#msgcon" onclick="toCopy();">回复</a>'.$row["time"].'</span></td> </tr> </table> </div>';}
将上面读出来的内容复制到textarea里 :
<script> function toCopy(){ var midval= document.getElementById("mid").innerHTML; var msg= document.getElementById("msgten").innerHTML; document.getElementById("msgcon").value = "回复"+midval+"楼"+"["+msg+"]"; document.getElementById("msgcon").focus(); }</script>
效果:
问题是 :文本框里显示的永远是数据库读出来的最后一条,也就是第13条,如何做到点哪个回复就把那条复制到框里
回复讨论(解决方案)
id="msgten"
你的id重复了,不能这样用的。
修改为这样看看
$sql="select * from massage where iid=$iid order by mid desc limit $offset,$pagesize";$result=$db->query($sql);$i = 0;while (($row=$result->fetch_assoc())!=false) { echo '<div id="msg'.$i.'"> <table width="800" height="auto" border="0" cellpadding="0" cellspacing="0" align="center" bgcolor="#FFFFFF"> <tr> <th scope="row" width="100" align="center"><strong id="mid'.$i.'">#'.$row["mid"].'</strong><br /><a href="data.php">'.$row["author"].'</a></th> <td><p id="msgten'.$i.'">'.$row["msg"].'</p><span><a href="#msgcon" onclick="toCopy('.$i.');">回复</a>'.$row["time"].'</span></td> </tr> </table> </div>'; $i++;}
<script> function toCopy(c){ var midval= document.getElementById("mid"+c).innerHTML; var msg= document.getElementById("msgten"+c).innerHTML; document.getElementById("msgcon").value = "回复"+midval+"楼"+"["+msg+"]"; document.getElementById("msgcon").focus(); }</script>
id="msgten"
你的id重复了,不能这样用的。
修改为这样看看
$sql="select * from massage where iid=$iid order by mid desc limit $offset,$pagesize";$result=$db->query($sql);$i = 0;while (($row=$result->fetch_assoc())!=false) { echo '<div id="msg'.$i.'"> <table width="800" height="auto" border="0" cellpadding="0" cellspacing="0" align="center" bgcolor="#FFFFFF"> <tr> <th scope="row" width="100" align="center"><strong id="mid'.$i.'">#'.$row["mid"].'</strong><br /><a href="data.php">'.$row["author"].'</a></th> <td><p id="msgten'.$i.'">'.$row["msg"].'</p><span><a href="#msgcon" onclick="toCopy('.$i.');">回复</a>'.$row["time"].'</span></td> </tr> </table> </div>'; $i++;}
<script> function toCopy(c){ var midval= document.getElementById("mid"+c).innerHTML; var msg= document.getElementById("msgten"+c).innerHTML; document.getElementById("msgcon").value = "回复"+midval+"楼"+"["+msg+"]"; document.getElementById("msgcon").focus(); }</script>
多谢大神,问题解决
id="msgten"
你的id重复了,不能这样用的。
修改为这样看看
$sql="select * from massage where iid=$iid order by mid desc limit $offset,$pagesize";$result=$db->query($sql);$i = 0;while (($row=$result->fetch_assoc())!=false) { echo '<div id="msg'.$i.'"> <table width="800" height="auto" border="0" cellpadding="0" cellspacing="0" align="center" bgcolor="#FFFFFF"> <tr> <th scope="row" width="100" align="center"><strong id="mid'.$i.'">#'.$row["mid"].'</strong><br /><a href="data.php">'.$row["author"].'</a></th> <td><p id="msgten'.$i.'">'.$row["msg"].'</p><span><a href="#msgcon" onclick="toCopy('.$i.');">回复</a>'.$row["time"].'</span></td> </tr> </table> </div>'; $i++;}
<script> function toCopy(c){ var midval= document.getElementById("mid"+c).innerHTML; var msg= document.getElementById("msgten"+c).innerHTML; document.getElementById("msgcon").value = "回复"+midval+"楼"+"["+msg+"]"; document.getElementById("msgcon").focus(); }</script>
大神,,我新提交的留言为什么不能复制到框里去呀
换个浏览器试试
什?意思,你新提交留言後,??到框?
你新提交的?入?後,然後?刷新?面,然後?重新列表。
如果是??流程是???的。除非你不是用post表?的方式提交,且?有刷新列表。
你新提交的?入?後,然後?刷新?面,然後?重新列表。
如果是??流程是???的。除非你不是用post表?的方式提交,且?有刷新列表。
我是用podt提交的,提交成功后跳转这个页面确实是刷新了
<form action="massage_save.php" method="post"> <div id="msgbox" onmouseover="this.style.borderColor='#2883B0'" onmouseout="this.style.borderColor='#CCC'" ><textarea name="msg" cols="107" rows="5" required="required"></textarea></div><br /> <input name="submit" type="submit" value="提交" id="button" style="height:40px;color:#FFF;font-size:14px; cursor:pointer"/> </form>
换个浏览器试试
好的,我回去试试
提交後刷新有什????
新的留言不能?回覆?
那??是你留言的?容有特殊字符了。
<script> <br /> function toCopy(c){ <br /> var midval= document.getElementById("mid"+c).innerHTML; <br /> var msg= document.getElementById("msgten"+c).innerHTML; <br /> //加一句,看看是否有? <br /> alert(midval + ' ' + msg); <br /> document.getElementById("msgcon").value = "回复"+midval+"楼"+"["+msg+"]"; <br /> document.getElementById("msgcon").focus(); <br /> } <br /> </script>
提交後刷新有什????
新的留言不能?回覆?
那??是你留言的?容有特殊字符了。
<script> <br /> function toCopy(c){ <br /> var midval= document.getElementById("mid"+c).innerHTML; <br /> var msg= document.getElementById("msgten"+c).innerHTML; <br /> //加一句,看看是否有? <br /> alert(midval + ' ' + msg); <br /> document.getElementById("msgcon").value = "回复"+midval+"楼"+"["+msg+"]"; <br /> document.getElementById("msgcon").focus(); <br /> } <br /> </script>
我运行了几遍,发现只有最后 从数据库输出的那条无效,点回复弹出白框
提交後刷新有什????
新的留言不能?回覆?
那??是你留言的?容有特殊字符了。
<script> <br /> function toCopy(c){ <br /> var midval= document.getElementById("mid"+c).innerHTML; <br /> var msg= document.getElementById("msgten"+c).innerHTML; <br /> //加一句,看看是否有? <br /> alert(midval + ' ' + msg); <br /> document.getElementById("msgcon").value = "回复"+midval+"楼"+"["+msg+"]"; <br /> document.getElementById("msgcon").focus(); <br /> } <br /> </script>
我运行了几遍,发现只有最后 从数据库输出的那条无效,点回复弹出白框
解决了。打开控制台发现最后一条回复的id没有$i,我把$i赋了初值1可以了。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.
