这是两个文件
Calling.php
<html>
<body>
<form action="Called.php" method="get">
<input type="button" name="B1" value="B1">
<input type="button" name="B2" value="B2">
<input type="Submit" name="Submit1"/>
<!-- <a href="http://www.google.com?act=google">Google</a>
<a href="http://www.yahoo.com?act=yahoo">yahoo</a>
-->
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
和Called.php
<?php
if(isset($_GET("Submit1")))
{
echo("<script>location.href = 'http://stackoverflow.com';</script>");
}
if(isset($_GET["B1"]))
{
echo("<script>location.href = 'http://google.com/';</script>");
exit();
}
if(isset($_GET["B2"]))
- List item
{
echo "<meta http-equiv='refresh' content='0;url=http://www.yahoo.com'>";
exit();
}
?>
Run Code Online (Sandbox Code Playgroud)
当我点击按钮"B1"和"B2"时,页面将闪烁,但现在重定向和第三个"提交"按钮将重定向到新页面,我在那里得到输出为"Called.php".
请花几秒钟为这个php初学者.
Gor*_*onM 10
您不能直接因为按钮单击是客户端活动而PHP是服务器端.如果您提交了所有输入,那么用户单击的那个将作为$ _GET数组的一部分提交,但只有当用户单击其中一个并且不提交表单时才会提交,例如,按文本中的Enter键输入.
您可以将AJAX事件附加到按钮,让它们触发PHP脚本以运行您要运行的功能,但这有一系列问题.
编辑:我应该注意,你的重定向方法至少可以说是不优雅的.你可以使用header()来进行重定向,它会比回复javascript更加清晰.