我有一个小的pm系统,并使用按钮来切换消息打开或关闭。如果没有打开的消息,则按钮显示'lesen‘。单击按钮将打开消息,文本将更改为'schliessen’。我可以打开每条消息,但不能关闭它们。消息关闭一次,然后再次打开,但是按钮文本仍然显示'lesen‘我希望你能理解我试图解释的:)这是我的代码:
这将在数据库中将打开的邮件设置为已读。
<script type="text/javascript">
function setRead($id){
$.ajax({
type: "POST",
url: "update_pm_status.php",
data: { id: $id}
});
}
这将打开或关闭邮件。
<script type="text/javascript">
function toggleOpenClose(id) {
$('#message-'+id).slideToggle("fast");
if(document.getElementById(id).innerHTML === "lesen") {
document.getElementById(id).innerHTML = "schließen";
} else {
document.getElementById(id).innerHTML = "lesen";
}}
<?php
while ($row = mysql_fetch_array($result)) {
?>
<form action="reply.php" method="post">
<p class="button"> <a class="open-close">
<div id="container">
<div class="item">
<span class="toggleOpen" onclick="setRead(this.id); toggleOpenClose(this.id);" id="<?php echo $row['id']; ?>" name="gelesen">lesen</span>
<div id="message-<?php echo $row['id'];?>" class="toggle">
<p><?php echo $row['nachricht']; ?></p>
<p><input class="button-link" type="submit" name="reply" value="Antworten"></form></p>
<p><form action="mailbox.php" method="post">
<input type="hidden" name="id" value="<?php echo $row['id']; ?>">
<input class="button-del" type="submit" name="delete_perm" style="vertical-align: top; margin-top: 20px;" value="Löschen"></p></form>为什么单击“关闭”后邮件不会保持关闭状态?
发布于 2014-08-02 16:34:27
我还没弄清楚出了什么问题。如果我使用
<script type="text/javascript">
$(function() {
$('span.toggleOpen').click(function() {
$(this).next('.toggle').slideDown("fast");
});
$('span.toggleClose').click(function() {
$(this).parents('.toggle').slideUp("fast");
});});
然后它就可以工作了,但我必须使用两个按钮(打开和关闭),而且这两个按钮总是显示出来的。我想要的是一个按钮,可以通过打开或关闭消息来更改文本。
https://stackoverflow.com/questions/25081979
复制相似问题