如何通过单击更改数组值?
How can I change an array value with a click?
我已经看到了对 Ajax 的引用,但我不完全确定如何将它与阵列集成并且仍然有一个正常运行的系统。我想在每次用户按下按钮时更改 $place 和 $title 的值,并且我知道我需要一个 if 语句和某种处理表单的方法(PHP 中没有点击),但是除此之外我什么都不知道。我在下面粘贴了 PHP 和 HTML 按钮:
<!DOCTYPE html>
<html>
<head>
<title>StatsCalc V1</title>
<link rel="stylesheet" type="text/css" href="sheen.css">
<link rel="script" type="text/javascript" href="slide.js">
<link rel="icon" type="image/png" href="favicon.ico">
<link href='http://fonts.googleapis.com/css?family=Raleway:500' rel='stylesheet' type='text/css'>
</head>
<body>
<?php
$place = 0;
$title = 0;
echo '<div class="boxes"><h1>Statistics Calculator: Version 1</h1></div>';
$links = array('<div class="fancyBoxes"><a href="standardisedForm.php"><img class="mainPic" src="normalDist.svg" alt="a normal distribution, courtesy openclipart.org"></a></div>', "", "");
echo $links[$place];
/*if($_GET){
if(isset($_GET['clickies'])){
$place = 1;
$title = 1;
}
}*/
if($_POST['clickies'] and $_SERVER['REQUEST_METHOD'] == "POST"){
$place = 1;
$title = 1;
}
$subtitle = array('<div class="boxes"><h1>Standardised Score</h1></div>', '<div class="boxes"><h1>Standard Deviation</h1></div>', '<div class="boxes"><h1>Averages</h1></div>');
echo $subtitle[$title];
?>
<input type="submit" id="clickies" name="clickies" value="" />
<script src="move.js"></script>
<script src="slide.js"></script>
<script src="jquery-1.11.2.js"></script>
<!--The calculator must be able to field standardised score, standard deviation, and averages (mean/median/mode)-->
<!--Headings will be assigned with an array; slides will be navigated with tabs on either side of the window-->
<!--Credit to https://openclipart.org/detail/171055/normal-distn-shaded-outside-1s-by-oderwald-171055 for the Standardised Score image/label thingy-->
</body>
</html>
<?php
$_SESSION["place"] = 0;
$place = 0;
$title = 0;
session_start();
echo '<div class="boxes"><h1>Statistics Calculator: Version 1</h1></div>';
$links = array('<div class="fancyBoxes"><a href="standardisedForm.php"><img class="mainPic" src="normalDist.svg" alt="a normal distribution, courtesy openclipart.org"> </a></div>', "", "");
if($_POST['clickies'] and $_SERVER['REQUEST_METHOD'] == "POST"){
$_SESSION["place"] = $_SESSION["place"] + 1;
$title = 1;
}
echo $links[$_SESSION["place"]];
$subtitle = array('<div class="boxes"><h1>Standardised Score</h1></div>', '<div class="boxes"><h1>Standard Deviation</h1></div>', '<div class="boxes"><h1>Averages</h1></div>');
echo $subtitle[$title];
?>
<form method="post" action="">
<input type="submit" id="clickies" name="clickies" value="submit" />
</form>
您可以使用 php.
的会话
也许这可以让您了解如何去做。
if($_SERVER['REQUEST_METHOD'] == "POST") {
if (isset($_POST['clickies'])) {
$count = intval($_POST['count']);
$count++;
$place = $count;
$title = $count;
}
} else {
$place = 0;
$title = 0;
}
echo '<div class="boxes"><h1>Statistics Calculator: Version 1</h1></div>';
$links = array('<div class="fancyBoxes"><a href="standardisedForm.php"><img class="mainPic" src="normalDist.svg" alt="a normal distribution, courtesy openclipart.org"></a></div>', "", "");
echo $links[$place];
echo $place; echo "<br/>";
$subtitle = array('<div class="boxes"><h1>Standardised Score</h1></div>', '<div class="boxes"><h1>Standard Deviation</h1></div>', '<div class="boxes"><h1>Averages</h1></div>');
echo $subtitle[$title];
?>
<form action="" method="POST">
<input type="submit" id="clickies" name="clickies" value="" />
<input type="hidden" id="count" name="count" value="<?php echo $place;?>" />
</form>
我所做的是需要将按钮放在一个表单中并放置一个方法= post
并将其提交到同一页面
我还将计数存储在隐藏的输入中,并在提交表单时始终传递它并更新其在表单上的值,
尽量根据自己的需要修改
我已经看到了对 Ajax 的引用,但我不完全确定如何将它与阵列集成并且仍然有一个正常运行的系统。我想在每次用户按下按钮时更改 $place 和 $title 的值,并且我知道我需要一个 if 语句和某种处理表单的方法(PHP 中没有点击),但是除此之外我什么都不知道。我在下面粘贴了 PHP 和 HTML 按钮:
<!DOCTYPE html>
<html>
<head>
<title>StatsCalc V1</title>
<link rel="stylesheet" type="text/css" href="sheen.css">
<link rel="script" type="text/javascript" href="slide.js">
<link rel="icon" type="image/png" href="favicon.ico">
<link href='http://fonts.googleapis.com/css?family=Raleway:500' rel='stylesheet' type='text/css'>
</head>
<body>
<?php
$place = 0;
$title = 0;
echo '<div class="boxes"><h1>Statistics Calculator: Version 1</h1></div>';
$links = array('<div class="fancyBoxes"><a href="standardisedForm.php"><img class="mainPic" src="normalDist.svg" alt="a normal distribution, courtesy openclipart.org"></a></div>', "", "");
echo $links[$place];
/*if($_GET){
if(isset($_GET['clickies'])){
$place = 1;
$title = 1;
}
}*/
if($_POST['clickies'] and $_SERVER['REQUEST_METHOD'] == "POST"){
$place = 1;
$title = 1;
}
$subtitle = array('<div class="boxes"><h1>Standardised Score</h1></div>', '<div class="boxes"><h1>Standard Deviation</h1></div>', '<div class="boxes"><h1>Averages</h1></div>');
echo $subtitle[$title];
?>
<input type="submit" id="clickies" name="clickies" value="" />
<script src="move.js"></script>
<script src="slide.js"></script>
<script src="jquery-1.11.2.js"></script>
<!--The calculator must be able to field standardised score, standard deviation, and averages (mean/median/mode)-->
<!--Headings will be assigned with an array; slides will be navigated with tabs on either side of the window-->
<!--Credit to https://openclipart.org/detail/171055/normal-distn-shaded-outside-1s-by-oderwald-171055 for the Standardised Score image/label thingy-->
</body>
</html>
<?php
$_SESSION["place"] = 0;
$place = 0;
$title = 0;
session_start();
echo '<div class="boxes"><h1>Statistics Calculator: Version 1</h1></div>';
$links = array('<div class="fancyBoxes"><a href="standardisedForm.php"><img class="mainPic" src="normalDist.svg" alt="a normal distribution, courtesy openclipart.org"> </a></div>', "", "");
if($_POST['clickies'] and $_SERVER['REQUEST_METHOD'] == "POST"){
$_SESSION["place"] = $_SESSION["place"] + 1;
$title = 1;
}
echo $links[$_SESSION["place"]];
$subtitle = array('<div class="boxes"><h1>Standardised Score</h1></div>', '<div class="boxes"><h1>Standard Deviation</h1></div>', '<div class="boxes"><h1>Averages</h1></div>');
echo $subtitle[$title];
?>
<form method="post" action="">
<input type="submit" id="clickies" name="clickies" value="submit" />
</form>
您可以使用 php.
的会话也许这可以让您了解如何去做。
if($_SERVER['REQUEST_METHOD'] == "POST") {
if (isset($_POST['clickies'])) {
$count = intval($_POST['count']);
$count++;
$place = $count;
$title = $count;
}
} else {
$place = 0;
$title = 0;
}
echo '<div class="boxes"><h1>Statistics Calculator: Version 1</h1></div>';
$links = array('<div class="fancyBoxes"><a href="standardisedForm.php"><img class="mainPic" src="normalDist.svg" alt="a normal distribution, courtesy openclipart.org"></a></div>', "", "");
echo $links[$place];
echo $place; echo "<br/>";
$subtitle = array('<div class="boxes"><h1>Standardised Score</h1></div>', '<div class="boxes"><h1>Standard Deviation</h1></div>', '<div class="boxes"><h1>Averages</h1></div>');
echo $subtitle[$title];
?>
<form action="" method="POST">
<input type="submit" id="clickies" name="clickies" value="" />
<input type="hidden" id="count" name="count" value="<?php echo $place;?>" />
</form>
我所做的是需要将按钮放在一个表单中并放置一个方法= post 并将其提交到同一页面
我还将计数存储在隐藏的输入中,并在提交表单时始终传递它并更新其在表单上的值,
尽量根据自己的需要修改