简体   繁体   English

如何在PHP代码中向可编辑按钮添加可折叠表单? 我尝试了一些东西,但是没有用

[英]How to add collapsible form to edit-button inside PHP code? I tried something, but didn't work

I have been trying for two weeks to add a collapsible button which should reveal the edit-form. 我已经尝试了两个星期来添加一个可折叠的按钮,该按钮应该显示编辑表单。 I found something, but that java code didn't work properly inside my PHP code . 我找到了一些东西,但是Java代码在我的PHP代码中无法正常工作 For example, it works two by two and it is very annoying. 例如,它的工作原理是两乘两下,这很烦人。

I tried to add another variables which could change that issue, but didn't work. 我试图添加另一个可以更改该问题的变量,但是没有起作用。 After that, worked three by three. 在那之后,工作三乘三。

<?php 
if(isset($_SESSION['id'])) {
  if($_SESSION['id'] == $row2['id']){

echo "<button type='submit' class='edit-comment'>Edit</button>
  <div class='content'><form class='content edit-form' method='POST' action='".editComments($conn)."'>
  <input type='hidden' name='comment_id' value='".$row['comment_id']."'>
    <input type='hidden' name='user_id' value='".$row['user_id']."'>
    <input type='hidden' name='date' value='".date('d-m-Y H:i:s')."'>
    <textarea class='comment' name='comment'>".$row['comment']."</textarea><br>
    <button id='edit' name='submite' type='submit'>Edit</button>
    </form></div>
    <script>
    var coll = document.getElementsByClassName('edit-comment');
    var i;

    for (i = 0; i < coll.length; i++) {
      coll[i].addEventListener('click', function() {
        this.classList.toggle('active');
        var content = this.nextElementSibling;
        if (content.style.maxHeight){
          content.style.maxHeight = null;
        } else {
          content.style.maxHeight = content.scrollHeight + 'px';
        }
      });
    }
    </script>"; ?>

I expect to reveal all the comments, but works just two by two. 我希望透露所有评论,但只能两个接一个地工作。 Here is a picture to understand better what I said: 这是一张图片,可以更好地理解我的意思:

I don't know if the following will be of interest as it's likely I have perhaps misunderstood the problem having not been able to view all the code at this point. 我不知道下面的内容是否会引起人们的兴趣,因为我可能无法正确理解当前无法查看所有代码的问题。 The following will create ( emulate the creation of ) several of these minimised/hidden forms and a single javascript listener is registed for all of them 以下将创建(模拟创建)这些最小化/隐藏形式中的几种,并为所有这些形式注册一个javascript侦听器

<!DOCTYPE html>
<html lang='en'>
    <head>
        <meta charset='utf-8' />
        <title>expanding forms</title>
        <style>
            html *{
                box-sizing:border-box;
                -webkit-transition: all 350ms ease-in-out;
                -moz-transition:    all 350ms ease-in-out;
                -ms-transition:     all 350ms ease-in-out;
                -o-transition:      all 350ms ease-in-out;
                transition:         all 350ms ease-in-out;          
            }
            .content{
                display:none;
                margin:1rem 0;
            }
            .expanded{
                min-height:10rem;
                max-height:10rem;
                height:10rem;
                display:block;
                border:1px solid black;
                padding:0.25rem;
            }
            .minimised{
                height:0rem;
            }
            button.edit-comment{display:block;}
            textarea{
                width:80%;
                height:9.25rem;
                margin:auto;
                resize:none;
            }
            form > button[type='submit']{
                float:right;
                width:10%;
                padding:1rem;
                background:gray;
                color:white;
            }
        </style>
        <script>
            document.addEventListener('DOMContentLoaded', e=>{
                Array.prototype.slice.call( document.querySelectorAll('button.edit-comment') ).forEach( function( bttn ){
                    bttn.addEventListener( 'click', function(e){
                        let div=this.nextElementSibling;
                            div.classList.toggle( 'expanded' )
                    });
                });
            });
        </script>
    </head>
    <body>
        <?php
            for( $i=1; $i <=10; $i++ ){
                printf("
                    <button type='submit' class='edit-comment'>Edit</button>
                    <div class='content'>
                        <form class='hidden-content edit-form' method='POST' action='%s'>
                            <input type='hidden' name='comment_id' value='%d'>
                            <input type='hidden' name='user_id' value='%d'>
                            <input type='hidden' name='date' value='%s'>
                            <textarea class='comment' name='comment'>%s</textarea>
                            <button name='sub' type='submit'>Edit</button>
                        </form>
                    </div>",

                    '',
                    $i,
                    $i,
                    date('d-m-Y H:i:s'),
                    'This is a comment #'.$i
                );
            }
        ?>
    </body>
</html>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我尝试使用 .map function 但它对我的代码不起作用 - I tried to use the .map function but it didn't work on my code php页面按钮没有重定向,我尝试使用ajax,但并没有完全理解它的背后 - php page button does not redirect , i tried using ajax but sort of didn't get the whole idea behind it onClick在表单内部不起作用? - onClick didn't work inside form? 我想使用位置功能将 class 添加到#cart-total-remove 我尝试了很多方法但没有奏效 - I want to add a class to #cart-total-remove with the location fonction i tried many ways but didn't work 为什么onclick()在button标记内不起作用? - Why onclick() didn't work inside the button tag? 如何在可折叠小部件中编辑内容? - How to edit Content inside Collapsible Widget? 我试图在浏览器中制作一个画家,但后来它制作了一个“橡皮擦”,但它不起作用,因为它不会改变颜色 - I tried to make a painter in browser, but then it went to making an 'eraser' it didn't work because it doesn't change the color 我尝试向其中添加Bootstrap下拉按钮, <a>但下拉菜单无法正常工作。</a> <a>我该怎么做呢?</a> - I tried to add a Bootstrap dropdown button to <a> but the dropdown menu wont work. How do I do this? 我尝试使用 fisher-yates shuffle 字符串,但没有奏效 - I tried using a fisher-yates shuffle for strings, but it didn't work 删除按钮不起作用 - Delete Button didn't work
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM