使用顺序

时间:2016-12-10 12:46:05

标签: javascript php jquery html ajax

当我点击'按钮pg1'它应该显示'按钮pg2'。当我点击'按钮pg2'它应该显示'按钮pg3'等等......但它不按我的方式工作。请帮助....
HTML代码

<html>
  <head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
 </head>
 <body>
    <div id="display"></div>
    <button id="pg1">button pg1</button>
    <script>
        $(document).ready(function(){
            $(document).on( "click", "#pg1", function( event ) {
                $("#pg1").hide();
                $.post("show.php",
                {
                    id: "pg2"
                },
                function(data,status){
                    document.getElementById("display").innerHTML = data;
                });
            });
        });
    </script>
</body>
</html>

show.php页码

<?php
    $id=$_REQUEST["id"];
    echo "
        <button id='$id'>button $id</button>
        ";
    $id = str_replace("pg", "", $id);
    $nxId = $id+1;
    echo "
    <script>
        $(document).ready(function(){
            $(document).on( 'click', '#pg$id', function( event ) {
                $.post('show.php',
                {
                    id: 'pg$nxId'
                },
                function(data,status){
                    document.getElementById('display').innerHTML = data;
                });
            });
        });
    </script> ";
?>

0 个答案:

没有答案