仅使用会话即使在页面刷新时如何将我的提交按钮颜色设置为红色
using just session how do set my submit button color red even when page refresh
我是 php 的新手,但在成就中我想通过提交表单按钮颜色设置为红色很长一段时间,即使页面重新加载我试过的代码
<?php
session_start();
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
$_SESSION["form_post"] = "Yes";
}
if(isset($_SESSION["form_post"]) && $_SESSION["form_post"] =="Yes")
{
echo yes;
}
echo '<style type="text/css">
.buttn-on-post {
color: red;
}
你的Phone号码
<input type="submit" class="<?php if(isset($_SESSION["form_post"])) { echo "buttn-on-post"; }
?>';
一切正常,但我的提交按钮颜色没有改变请谁能解决这个问题?提前致谢
试试下面的例子: 在 session
中设置按钮颜色
<?php
session_start(); // start session
$_SESSION['color'] = "";
/* Condition for check button is clicked */
if(isset($_POST['submit'])) {
$_SESSION['color'] = "red";
}
?>
<!-- HTML Form -->
<form action="" method="POST">
<input type="submit" name="submit" value="submit" style="background-color:
<?php echo $_SESSION['color']; ?>">
</form>
您必须在 $_SESSION
超全局变量中存储一个变量,如下所示:
<?php
session_start();
// default color
if(!isset( $_SESSION['submitColor'])) $_SESSION['submitColor'] = 'black';
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
$_SESSION["form_post"] = "Yes";
// set the color as red in the session
$_SESSION['submitColor'] = 'red';
}
if(isset($_SESSION["form_post"]) && $_SESSION["form_post"] =="Yes")
{
echo yes;
}
echo "<style type=\"text/css\">
.buttn-on-post {
background-color: {$_SESSION['submitColor']};
}
</style>";
?>
<form method='post'>
<input type="submit" class="<?php if(isset($_SESSION["form_post"])) { echo "buttn-on-post"; }?>">
</form>
注意:第一次打开你的网页时,没有$_SESSION["form_post"]
变量,会在第一个用户[=20]之后设置=]行动。
我是 php 的新手,但在成就中我想通过提交表单按钮颜色设置为红色很长一段时间,即使页面重新加载我试过的代码
<?php
session_start();
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
$_SESSION["form_post"] = "Yes";
}
if(isset($_SESSION["form_post"]) && $_SESSION["form_post"] =="Yes")
{
echo yes;
}
echo '<style type="text/css">
.buttn-on-post {
color: red;
}
你的Phone号码
<input type="submit" class="<?php if(isset($_SESSION["form_post"])) { echo "buttn-on-post"; }
?>';
一切正常,但我的提交按钮颜色没有改变请谁能解决这个问题?提前致谢
试试下面的例子: 在 session
中设置按钮颜色<?php
session_start(); // start session
$_SESSION['color'] = "";
/* Condition for check button is clicked */
if(isset($_POST['submit'])) {
$_SESSION['color'] = "red";
}
?>
<!-- HTML Form -->
<form action="" method="POST">
<input type="submit" name="submit" value="submit" style="background-color:
<?php echo $_SESSION['color']; ?>">
</form>
您必须在 $_SESSION
超全局变量中存储一个变量,如下所示:
<?php
session_start();
// default color
if(!isset( $_SESSION['submitColor'])) $_SESSION['submitColor'] = 'black';
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
$_SESSION["form_post"] = "Yes";
// set the color as red in the session
$_SESSION['submitColor'] = 'red';
}
if(isset($_SESSION["form_post"]) && $_SESSION["form_post"] =="Yes")
{
echo yes;
}
echo "<style type=\"text/css\">
.buttn-on-post {
background-color: {$_SESSION['submitColor']};
}
</style>";
?>
<form method='post'>
<input type="submit" class="<?php if(isset($_SESSION["form_post"])) { echo "buttn-on-post"; }?>">
</form>
注意:第一次打开你的网页时,没有$_SESSION["form_post"]
变量,会在第一个用户[=20]之后设置=]行动。