我正在用 php 开发一个像 facebook 这样的社交网站。我有一个页面用于显示带有两个链接的用户消息,即reply
在delete
收件箱中每条消息的右下角。我的问题是,当我单击reply
链接时,两个链接的文本都应更改为post
和。back
我的 html 代码是这样的:
<div class="msgutil">
<a href="" id="reply" >reply</a>
<a href="delete_message.php?msg_id=<?php echo $row_msg_id;?>" id="delete">delete</a>//dont check this
</div><!--end msgutil-->
我的javascript代码是这样的:
$(document).ready(function()
{
//action to be done if link name is reply which is present below the message box
$("#reply").click(function(e)
{
//action to be done if link name has changed from "reply" to "post" which is present below the message box
if(document.getElementById('reply').innerHTML=="reply")
{
document.getElementById('reply').innerHTML="Post";
document.getElementById('delete').innerHTML="Back";
var idstr = document.getElementById('sender_id').value;
$('<br/><form id="msgreply" name="msgreply" action="post_messages.php" method="post"> <label for="txt_subject"><strong>Subject:</strong></label><br/><input type="text" id="txt_subject" name="txt_subject"/><br/><label for="txt_message"><strong>Message:</strong></label><br/><input type="hidden" id="to_id" name="to_id" value="'+idstr+'"/><textarea name="txt_message" id="replyfield"></textarea></form>').insertAfter("#temp");
e.stopPropagation();
e.preventDefault();
}
else if(document.getElementById('reply').innerHTML=="Post")
{
var message = document.getElementById('msgreply');
message.submit();
e.stopPropagation();
e.preventDefault();
}
});
//action to be done if link name is delete which is present below the message box
$("#delete").click(function(e)
{
//action to be done if link name has changed from "reply" to "post" which is present below the message box
if(document.getElementById('delete').innerHTML=="Back")
{
$("#msgreply").remove();
document.getElementById('reply').innerHTML="reply";
document.getElementById('delete').innerHTML="delete";
e.stopPropagation();
e.preventDefault();
}
});
});
它适用于第一条消息。如果收件箱中有多条消息,单击除第一条以外的任何消息的回复按钮时,不会发生任何操作。