<form action="index.php" method="post" target="_self"><input name="name" id="name" type="hidden" value="aaa" /><input type="submit" value="aaa" style="border:none;"></form>
<form action="index.php" method="post" target="_self"><input name="name" id="name" type="hidden" value="bbb" /><input type="submit" value="bbb" style="border:none;"></form>
<form action="index.php" method="post" target="_self"><input name="name" id="name" type="hidden" value="ccc" /><input type="submit" value="ccc" style="border:none;"></form>有三组按钮,分别传递值到当前页的指定标签<p>里面,替换原先的值。
比如打开index.php时,<p>标签显示为ddd,当按下aaa按钮时,<p>标签里的字被替换成aaa,当按下bbb按钮时,<p>标签里的字被替换成bbb,当按下ccc按钮时,<p>标签里的字被替换成ccc。
这个该怎样替换?<p>ddd<?php echo $_POST["name"]; ?></p>

解决方案 »

  1.   

    <p> 标签?这个要用js来控制。
      

  2.   


    <script language="javascript">
    function sub(val)
    {
    document.getElementById("name").value =val;
    }
    </script>
    <form action="index.php" method="post" target="_self">
    <input name="name" id="name" type="hidden" value="" />
    <input type="submit" value="aaa" style="border:none;" onclick="sub('aaa')">
    <input type="submit" value="bbb" style="border:none;" onclick="sub('bbb')">
    <input type="submit" value="ccc" style="border:none;" onclick="sub('ccc')">
    </form><p><?php echo $_POST["name"]; ?></p>
      

  3.   

    感谢heyli,不过<p>标签里的默认值为ddd,应该怎么添加呢?
    比如打开index.php时,<p>标签里已经显示ddd了。
      

  4.   

    <p><?php echo isset($_POST["name"])?$_POST['name']:'ddd'; ?></p>