gpt4 book ai didi

javascript - 遍历一组表单并在单击按钮时显示相应的表单

转载 作者:行者123 更新时间:2023-11-27 22:55:14 26 4
gpt4 key购买 nike

我的评论部分有一个“回复”按钮。如果单击回复按钮,我想显示适当的表格。 (评论最多5条)

我试过下面的代码,但它对我不起作用

var comment = document.getElementsByClassName('showreply');

function replyComment() {
var i;
for(i = 0; i <= comment.lenght; i++) {
comment[i].style.display='block';
}
}

当我点击回复按钮时,没有任何反应......

让我进一步打破这个问题。

我有一个网页,当有人访问它时(登录用户或 guest )显示一个文件(存储在数据库中)。

显示文件后,接下来是文件的注释(也存储在数据库中)。每条评论都有一个显示“回复”的按钮和一个位于 div 中的回复表单。默认情况下,div 是隐藏的。

请注意,评论多于 1。所以,我想在点击回复按钮时显示适当的回复表单...

任何人都知道实现此目标的更好方法。

我希望下面的代码能帮助您理解我在寻找什么...

<div class="music_comments">
<div class="comment_title"><i class="far fa-comments"></i> Comments (<?php echo $mcCount; ?>)</div>

<!-- Music Comments -->
<?php
while ($mccinfo = mysqli_fetch_array($mComments)) {
$ppid = $mccinfo['ID'];
$p = $mccinfo['poster'];

if($p != 'Guest') {
$poster = getUserInfo2($mccinfo['poster'], 'firstname'). ' ' . getUserInfo2($mccinfo['poster'], 'lastname');
$photo = getUserInfo2 ($p, 'photo');
$r = "<a href='/$p' title='$poster'>$poster</a>";
} else {
$poster = 'Guest';
$photo = '/images/avatar/avatar5.png';
$r = $poster;
}


$comment = $mccinfo['comment'];
$date = $mccinfo['date'];
$cq = mysqli_query($conn, "SELECT * FROM banabase_musiccommentreply WHERE commentID=$ppid AND musicID=$id");

$clikecount = mysqli_num_rows( mysqli_query($conn, "SELECT * FROM banabase_musicreaction WHERE type=1 AND commentID=$ppid AND musicID=$id"));

$cdislikecount = mysqli_num_rows( mysqli_query($conn, "SELECT * FROM banabase_musicreaction WHERE type=2 AND commentID=$ppid AND musicID=$id"));

$k = (str_shuffle('ABCDEFGHabcdefgh1234567890'));
$resetCode = substr ($k, 0, round(strlen($k)/2, 1));

$k2 = md5 (rand(000000, 999999));
$k3 = md5 (rand(000000, 999999));
$resetCode2 = substr ($k2, 0, round(strlen($k2)/5, 1));
$resetCode3 = substr ($k3, 0, round(strlen($k3)/5, 1));

$r2 = $resetCode2;
$r3 = $resetCode3;

$r1 = $r2. $ppid . $resetCode;
$r3 = $r3. $id . $resetCode;


echo "<div class='comment'>
<table cellspacing='5' cellpadding='2'>
<tr>
<td width='6%'>
<img src='$photo' height='50' width='50' alt='+' title='$poster'>
</td>
<td width='94%'>
<p style='margin-top: -2px; margin-bottom: 7px;'>
<small>
$r said:
</small>
<span class='msgtime right'>".timeAgo($date)."<span>
</p>
$comment<br>"; ?>
<small class='comment-action right'>
<a href='/music/react.php?like&cid=<?php echo $r1.'&mid='.$r3; ?>' title='Like'><i class='far fa-thumbs-up'></i></a> <?php echo $clikecount; ?> &nbsp;&nbsp;&nbsp; <a href='/music/react.php?dislike&cid=<?php echo $r1.'&mid='.$r3; ?>' title='Dislike'><i class='far fa-thumbs-down'></i></a> <?php echo $cdislikecount; ?> &nbsp;&nbsp;&nbsp; <a href='#reply' onclick="showForm();" title='Reply this comment'>Reply</a>
</small>


<?php echo "</td>
</tr>
</table>"; ?>


<!-- 1st Comment Reply Form -->
<div id='comment-reply' class="showreply">
<div id="reply" style="position: relative; top: -110px;"></div>
<center>
<form action="<?php echo htmlspecialchars('#'); ?>" method="post">
<h4 style="margin-bottom: 3px; color: #aaa;">Reply this Comment</h4>
<input type="hidden" name="poster" value="<?php if(isLoggedIn()) echo $user; else echo 'Guest'; ?>">
<input type="hidden" name="musicID" value="<?php echo $id; ?>">
<input type="hidden" name="commentID" value="<?php echo $ppid; ?>">
<textarea name='comment' width='40' rows='3'></textarea><br>
<input type="submit" name="reply" class="btn success" value="Reply">
</form>
</center>
</div>

<!-- First Comment Reply-->
<?php
while ($cr = mysqli_fetch_array($cq)) {

$r = $cr['ID'];
$rp = $cr['poster'];
$rrrcq = mysqli_query($conn, "SELECT * FROM banabase_musiccommentreply WHERE commentID=$r AND musicID=$id");

if($rp != 'Guest') {
$prp = getUserInfo2($cr['poster'], 'firstname'). ' ' . getUserInfo2($cr['poster'], 'lastname');
$rphoto = getUserInfo2 ($rp, 'photo');
$rpl = "<a href='/$rp' title='$prp'>$prp</a>";
} else {
$prp = 'Guest';
$rphoto = '/images/avatar/avatar5.png';
$rpl = $prp;
}

$rc = $cr['comment'];
$rd = $cr['date'];

$rlikecount = mysqli_num_rows( mysqli_query($conn, "SELECT * FROM banabase_musicreaction WHERE type=1 AND commentID=$r AND musicID=$id"));

$rdislikecount = mysqli_num_rows( mysqli_query($conn, "SELECT * FROM banabase_musicreaction WHERE type=2 AND commentID=$r AND musicID=$id"));

$k = (str_shuffle('ABCDEFGHabcdefgh1234567890'));
$resetCode = substr ($k, 0, round(strlen($k)/2, 1));

$k2 = md5 (rand(000000, 999999));
$k3 = md5 (rand(000000, 999999));
$resetCode2 = substr ($k2, 0, round(strlen($k2)/5, 1));
$resetCode3 = substr ($k3, 0, round(strlen($k3)/5, 1));

$r2 = $resetCode2;
$r3 = $resetCode3;

$r1 = $r2. $r . $resetCode;
$r3 = $r3. $id . $resetCode;

echo "<div class='comment' style='margin-left: 40px; background: #eee;'>
<table cellspacing='5' cellpadding='2'>
<tr>
<td width='6%'>
<img src='$rphoto' height='50' width='50' alt='+' title='$prp'>
</td>
<td width='94%'>
<p style='margin-top: -2px; margin-bottom: 7px;'>
<small>
$rpl replied:
</small>
<span class='msgtime right'>".timeAgo($rd)."<span>
</p>
$rc<br>"; ?>

<small class='comment-action right'>
<a href='/music/react.php?like&cid=<?php echo $r1.'&mid='.$r3; ?>' title='Like'><i class='far fa-thumbs-up'></i></a> <?php echo $rlikecount; ?> &nbsp;&nbsp;&nbsp; <a href='/music/react.php?dislike&cid=<?php echo $r1.'&mid='.$r3; ?>' title='Dislike'><i class='far fa-thumbs-down'></i></a> <?php echo $rdislikecount; ?> &nbsp;&nbsp;&nbsp; <a href='#reply' onclick="showForm();" title='Reply this comment'>Reply</a>
</small>

<!-- Second Comment Reply Form-->
<div id='comment-reply' class="showreply">
<div id="reply" style="position: relative; top: -110px;"></div>
<center>
<form action="<?php echo htmlspecialchars('#'); ?>" method="post">
<h4 style="margin-bottom: 3px; color: #aaa;">Reply this Comment</h4>
<input type="hidden" name="poster" value="<?php if(isLoggedIn()) echo $user; else echo 'Guest'; ?>">
<input type="hidden" name="musicID" value="<?php echo $id; ?>">
<input type="hidden" name="commentID" value="<?php echo $r; ?>">
<textarea name='comment' width='40' rows='3'></textarea><br>
<input type="submit" name="reply" class="btn success" value="Reply">
</form>
</center>
</div>

<!-- Second Comment Reply-->

<?php echo "
</td>
</tr>
</table>";


while ($rrrcr = mysqli_fetch_array($rrrcq)) {
$rrrr = $rrrcr['ID'];
$rrrrp = $rrrcr['poster'];
$rrcq = mysqli_query($conn, "SELECT * FROM banabase_musiccommentreply WHERE commentID=$rrrr AND musicID=$id");

if($rrrrp != 'Guest') {
$rrrprp = getUserInfo2($rrrcr['poster'], 'firstname'). ' ' . getUserInfo2($rrrcr['poster'], 'lastname');
$rrrrphoto = getUserInfo2 ($rrrrp, 'photo');
$rrrrpl = "<a href='/$rp' title='$rrrprp'>$rrrprp</a>";
} else {
$rrrprp = 'Guest';
$rrrrphoto = '/images/avatar/avatar5.png';
$rrrrpl = $rrrprp;
}

$rrrrc = $rrrcr['comment'];
$rrrrd = $rrrcr['date'];

$r2likecount = mysqli_num_rows( mysqli_query($conn, "SELECT * FROM banabase_musicreaction WHERE type=1 AND commentID=$rrrr AND musicID=$id"));

$r2dislikecount = mysqli_num_rows( mysqli_query($conn, "SELECT * FROM banabase_musicreaction WHERE type=2 AND commentID=$r AND musicID=$id"));

$k = (str_shuffle('ABCDEFGHabcdefgh1234567890'));
$resetCode = substr ($k, 0, round(strlen($k)/2, 1));

$k2 = md5 (rand(000000, 999999));
$k3 = md5 (rand(000000, 999999));
$resetCode2 = substr ($k2, 0, round(strlen($k2)/5, 1));
$resetCode3 = substr ($k3, 0, round(strlen($k3)/5, 1));

$r2 = $resetCode2;
$r3 = $resetCode3;

$r1 = $r2. $rrrr . $resetCode;
$r3 = $r3. $id . $resetCode;


echo "<div class='comment' style='margin-left: 40px;'>
<table cellspacing='5' cellpadding='2'>
<tr>
<td width='6%'>
<img src='$rrrrphoto' height='50' width='50' alt='+' title='$rrrprp'>
</td>
<td width='94%'>
<p style='margin-top: -2px; margin-bottom: 7px;'>
<small>
$rrrrpl replied:
</small>
<span class='msgtime right'>".timeAgo($rrrrd)."<span>
</p>
$rrrrc<br>"; ?>

<small class='comment-action right'>
<a href='/music/react.php?like&cid=<?php echo $r1.'&mid='.$r3; ?>' title='Like'><i class='far fa-thumbs-up'></i></a> <?php echo $r2likecount; ?> &nbsp;&nbsp;&nbsp; <a href='/music/react.php?dislike&cid=<?php echo $r1.'&mid='.$r3; ?>' title='Dislike'><i class='far fa-thumbs-down'></i></a> <?php echo $r2dislikecount; ?> &nbsp;&nbsp;&nbsp; <a href='#reply' onclick="showForm();" title='Reply this comment'>Reply</a>
</small>

<!-- Other Comment Reply Form-->

<div id='comment-reply' class="showreply">
<div id="reply" style="position: relative; top: -110px;"></div>
<center>
<form action="<?php echo htmlspecialchars('#'); ?>" method="post">
<h4 style="margin-bottom: 3px; color: #aaa;">Reply this Comment</h4>
<input type="hidden" name="poster" value="<?php if(isLoggedIn()) echo $user; else echo 'Guest'; ?>">
<input type="hidden" name="musicID" value="<?php echo $id; ?>">
<input type="hidden" name="commentID" value="<?php echo $rrrr; ?>">
<textarea name='comment' width='40' rows='3'></textarea><br>
<input type="submit" name="reply" class="btn success" value="Reply">
</form>
</center>
</div>

<?php echo "
</td>
</tr>
</table>";

while ($rrcr = mysqli_fetch_array($rrcq)) {
$rrr = $rrcr['ID'];
$rrrp = $rrcr['poster'];

if($rrrp != 'Guest') {
$rrprp = getUserInfo2($rrcr['poster'], 'firstname'). ' ' . getUserInfo2($rrcr['poster'], 'lastname');
$prrphoto = getUserInfo2 ($rrrp, 'photo');
$rrrpl = "<a href='/$rrrp' title='$rrprp'>$rrprp</a>";
} else {
$rrprp = 'Guest';
$prrphoto = '/images/avatar/avatar5.png';
$rrrpl = $rrprp;
}
$prrc = $rrcr['comment'];
$rrrd = $rrcr['date'];


$r3likecount = mysqli_num_rows( mysqli_query($conn, "SELECT * FROM banabase_musicreaction WHERE type=1 AND commentID=$rrr AND musicID=$id"));

$r3dislikecount = mysqli_num_rows( mysqli_query($conn, "SELECT * FROM banabase_musicreaction WHERE type=2 AND commentID=$rrr AND musicID=$id"));

$k = (str_shuffle('ABCDEFGHabcdefgh1234567890'));
$resetCode = substr ($k, 0, round(strlen($k)/2, 1));

$k2 = md5 (rand(000000, 999999));
$k3 = md5 (rand(000000, 999999));
$resetCode2 = substr ($k2, 0, round(strlen($k2)/5, 1));
$resetCode3 = substr ($k3, 0, round(strlen($k3)/5, 1));

$r2 = $resetCode2;
$r3 = $resetCode3;

$r1 = $r2. $rrr . $resetCode;
$r3 = $r3. $id . $resetCode;


echo "<div class='comment' style='margin-left: 40px; background: #eeee;'>
<table cellspacing='5' cellpadding='2'>
<tr>
<td width='6%'>
<img src='$prrphoto' height='50' width='50' alt='+' title='$rrprp'>
</td>
<td width='94%'>
<p style='margin-top: -2px; margin-bottom: 7px;'>
<small>
$rrrpl replied:
</small>
<span class='msgtime right'>".timeAgo($rrrd)."<span>
</p>
$prrc<br>"; ?>

<small class='comment-action right'>
<a href='/music/react.php?like&cid=<?php echo $r1.'&mid='.$r3; ?>' title='Like'><i class='far fa-thumbs-up'></i></a> <?php echo $r3likecount; ?> &nbsp;&nbsp;&nbsp; <a href='/music/react.php?dislike&cid=<?php echo $r1.'&mid='.$r3; ?>' title='Dislike'><i class='far fa-thumbs-down'></i></a> <?php echo $r3dislikecount; ?>
</small>

<?php
echo "
</td>
</tr>
</table>
</div>";
}
echo "
</td>
</tr>
</table>
</div>";
}

echo "
</div>";
}

echo "
</div>";
}

?>
</div>
<div id="addcomment" style="position: relative; top: -70px;"></div>
<center>
<form action="<?php echo htmlspecialchars('#'); ?>" method="post">
<h4 style="margin-bottom: 3px; color: #aaa;">Add a Comment</h4>
<input type="hidden" name="poster" value="<?php if(isLoggedIn()) echo $user; else echo 'Guest'; ?>">
<input type="hidden" name="musicID" value="<?php echo $id; ?>">
<textarea name='comment' width='40' rows='3'></textarea><br>
<input type="submit" name="submit" class="btn success" value="Comment">
</form>
</center>

最佳答案

您在 comment.length 中拼错了“长度”一词,作为旁注,您可能希望将该变量名称更改为“评论”,因为它包含多个评论。

此外,如上所述,您不需要 <= , <应该足够了。

关于javascript - 遍历一组表单并在单击按钮时显示相应的表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56460676/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com