现在这是我的 html 按钮
<html>
<head>
</head>
<body>
<div>
<button type="button">change header</button>
</div
</body></html>
what i want is when i click on it change the variable
示例
<?php
$var= "path1";
$new= "path2";
if ( some one clicked the button) !== false) {
$var = $new;
header('Location: $var');
} else {
header('Location: $var');
}
?>
如果有javascript的方法请发布
最佳答案
使用 PHP,您可以尝试以下操作:
<form action="" method="post">
<input type="hidden" value="t">
<button>change header</button>
</form>
添加帖子检查以查看页面是否已发布。
<?php
$var= "hello world";
$new= "i hate world";
if ( $_POST ) {
$var= $new;
echo $var;
} else {
echo $var;
}
但我的猜测是,你确实在寻找一种 JS 方法来做到这一点。
关于javascript - 使用 html 按钮更改 php 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45771006/