0

嗨,我的代码类似于以下结构。

用更简单的方式来说,当我在文本框上输入一些东西('Hello World')并点击One它时,它会根据我输入的内容以及消息form two is here!TapMe按钮给我一个输出。

现在其次(问题出在哪里),如果我单击TapMe按钮,原始文本框输出('Hello Word')就会消失。我需要保留它而不会在屏幕上丢失它!

有什么建议么?谢谢!

<DOCTYPE html>
<html>
    <head>
        <title></title>
    </head>
    <body>
        <div id="one" style="width:300px; background:gray;">
            <form method="post" action="#">
                <input type="text" name="txt1" id="txt1">
                <input type="submit" name="sendtwo" id="sendtwo" value="One">

            </form>
        </div>

        <div id="two" style="width:300px; background:yellow;">
            <?php
            if(isset($_POST['sendtwo']))
            {   if($_POST['txt1'] == '')
                {echo 'txt1 is empty!'; return;} else {echo $_POST['txt1'];}
            }
            if(isset($_POST['sendt']) || isset($_POST['sendtwo']))
            {echo "<table border='1'><tr><td>form 2 is here!</rd></tr>"; 
            ?>
            <form method="post" action="#">
                <?php echo "<tr><td><input type='submit' name='sendt' id='sendt' value='TapMe'></td></tr></table>";}
                if(isset($_POST['sendt'])) {echo "You hit TapMe"; return;}
                ?>
            </form>
        </div>
    </body>
</html>
4

1 回答 1

0

在我制作这段代码时,你关闭了你之前的(同样的问题)。

至于,我是怎么做到的。sessions好吧,如果您对他们一无所知,请查找。

<DOCTYPE html>
<html>
    <head>
        <title></title>
    </head>
    <body>
        <div id="one" style="width:300px; background:gray;">
            <form method="post" action="#">
                <input type="text" name="txt1" id="txt1">
                <input type="submit" name="sendtwo" id="sendtwo" value="One">

            </form>
        </div>

        <div id="two" style="width:300px; background:yellow;">
        <?php   session_start(); ?>

            <?php
            if(isset($_POST['sendtwo']))
            {   if($_POST['txt1'] == '')
                {echo 'txt1 is empty!'; return;} else {$_SESSION['loged'] = $_POST['txt1'];}
            }
            if(isset($_POST['sendt']) || isset($_POST['sendtwo']))
            {if(isset($_SESSION['loged'])) echo $_SESSION['loged']; echo "<table border='1'><tr><td>form 2 is here!</rd></tr>"; 
            ?>
            <form method="post" action="#">
                <?php echo "<tr><td><input type='submit' name='sendt' id='sendt' value='TapMe'></td></tr></table>";}
                if(isset($_POST['sendt'])) {echo "You hit TapMe";} 

                ?>


            </form>
        </div>
    </body>
</html> 
于 2013-05-26T11:37:05.570 回答