【发布时间】:2017-01-09 00:11:55
【问题描述】:
场景: 我试图让我的页面的一部分持续运行一个功能,然后单击上述按钮时该功能会受到影响。 按钮调用 main/constant 函数中的函数;大师($选定)。
这是我尝试过的。 index.php:
<? session_start();
require("inc.ini.php");
?>
<!doctype html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="styles.css">
<meta charset="utf-8">
<title>Buttons to funtions</title>
</head>
<body>
<main>
<header>
<form method="post" action="<?=$_SERVER['php_self']?>">
<button type="submit" name="change" value="insert, <?$selected = "func1";?>">Func 1</button>
<button type="submit" name="change" value="insert, <?$selected = "func2";?>">Func 2</button>
</form>
<!--
I want to press a button and when it is pressed it calls the function selected and gives it the value of which the button represents.
-->
</header>
<figure>
<?
if($_POST['change']){
echo $selected;
master($selected);
}
?>
</figure>
</main>
</body>
</html>
inc.ini.php:
<? session_start();
function master($selected){
if($selected == "func1"){
function func1(){
echo "func 1";
}
}
if($selected == "func2"){
function func2(){
echo "func 2";
}
}
}
?>
另一个问题。我需要做这些 if 语句吗,$selector 可以直接跳转到新函数吗?
【问题讨论】:
-
你似乎需要 javascript 和 ajax...或者重命名提交按钮。