Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/438.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何为数据库中的php选择添加向下/向上滑动功能?_Javascript_Php_Jquery - Fatal编程技术网

Javascript 如何为数据库中的php选择添加向下/向上滑动功能?

Javascript 如何为数据库中的php选择添加向下/向上滑动功能?,javascript,php,jquery,Javascript,Php,Jquery,我一直在尝试将向上/向下滑动功能添加到一个PHPSelect表中,但不幸的是,我似乎遗漏了一些东西 我的代码已经有了一个向上/向下滑动的函数init,它与textarea和submit按钮相关。现在,我需要相同的函数用于问答行。表1给出了问题,表2给出了答案 我会把这个问题作为一个链接,这样当我们点击它时,表2中的答案列表就会向下滑动 我的代码如下: <div class="name"> <?php

我一直在尝试将向上/向下滑动功能添加到一个PHPSelect表中,但不幸的是,我似乎遗漏了一些东西

我的代码已经有了一个向上/向下滑动的函数init,它与textarea和submit按钮相关。现在,我需要相同的函数用于问答行。表1给出了问题,表2给出了答案

我会把这个问题作为一个链接,这样当我们点击它时,表2中的答案列表就会向下滑动

我的代码如下:

<div class="name">

                            <?php 
                            $sql = "SELECT * FROM input ORDER BY date DESC";
                            $result = $conn->query($sql);

                            if ($result->num_rows > 0) { 
                            $index = 0; 
                            while($row = $result->fetch_assoc()) { 
                              $index++; 
                            $myid = $row["id"] ;
                            $sql2 = "SELECT * FROM output WHERE question_id = $myid ORDER BY date DESC";

                            $result2 = $conn->query($sql2);


                            ?>

    <div id="q">
        <B><big><font color= #ba4a00> Q:</font></big><a class="About" href="#" class="question" id="question_'.$index.'"> <?php echo $row["question"]; ?></a> </B>

                    <?php 
                            echo '<button class="add" id="add_'.$index.'"><B>Add Answer</B></button>';
                            echo '<form style="display:none;" name="answer_'.$index.'" method="post" action="output.php">'; // I dont think openning form from row to row would be nice!
                            echo '<input type="hidden" name="questionid" value="'. $row['id'].'"/>';
                            echo '<textarea  type="text" class="addtext" name="addtext" required id="addtext_'.$index.'" placeholder="Please type your answer here.."  ></textarea>';
                            echo '<button onClick="addsubmit('.$index.');" type="submit" id="addsubmit_'.$index.'" class="addsubmit"><B>Submit</B></button>';
                            echo '</form>';
                        ?>
        <small><p><?php echo $row["date"]; ?></p></small>

        <?php 

            if ($result2->num_rows > 0) {
            while($row2 = $result2->fetch_assoc()) {
        ?>
        <div name="answ" id="answ_'.$index.'">
        <B><big><font color= #ba4a00> A:</font></B></big> <small><?php echo $row2["answer"]; ?></small></br>
        </div>


        <?php 
                }
            } else {
                    echo "No Answers Yet";
                        }


        ?>

    </div>
    <?php     }
                 } else {
                    echo "0 results";
                        }
                    $conn->close();
    ?>
</div>

<script type='text/javascript'>
$(document).ready(function() {
        $('.question').click(function(e) {
                e.stopPropagation();
            e.preventDefault();
            $(this).parent().find('answ').slideDown('slow');
        });


        $(window).click(function(e) {
            console.log( $(e.target) );
            if( !$(e.target).is('answ') ){
            $('answ').slideUp();
          } 

        });
    });

</script>

<script type='text/javascript'>
$(document).ready(function() {
        $('.add').click(function(e) {
                e.stopPropagation();
            e.preventDefault();
            $(this).parent().find('form').slideDown('slow');
            $(this).parent().find('form textarea.addtext').focus();
            $(this).hide();
        });

        $('form').click(function(e){
            e.stopPropagation();
        });

        $(window).click(function(e) {
            console.log( $(e.target) );
            if( !$(e.target).is('form') ){
            $('.add').show();
            $('form').slideUp();
          } 

        });
    });

</script>

问:

在PHP中,只有在为jquery编写委托函数的情况下,jquery上的动态选择才会对动态元素起作用

像这样编写函数,它将在元素上工作

$(document).on('click', '.question', function(e) {
    e.stopPropagation();
    e.preventDefault();
    $(this).parent().find('answ').slideDown('slow');
});

在PHP中,只有在为jquery编写委托函数的情况下,jquery上的动态选择才会对动态元素起作用

像这样编写函数,它将在元素上工作

$(document).on('click', '.question', function(e) {
    e.stopPropagation();
    e.preventDefault();
    $(this).parent().find('answ').slideDown('slow');
});

你这是什么意思?当点击问题时,我需要一个向下/向上滑动的功能来回答问题…你的意思是像JSFIDLE一样…?你能看一看这个搭档吗…你这是什么意思?当点击问题时,我需要一个向下/向上滑动的功能来回答问题…你的意思是像JSFIDLE一样…?你能看一下这个搭档吗。。