【发布时间】:2018-02-26 09:31:16
【问题描述】:
在下面的函数中,如果输入是蓝色的,那么它给出的结果是:“标题内容在这里你最喜欢的颜色是蓝色!”而它应该给出 - “你最喜欢的颜色是蓝色!”,请帮我纠正它。如果输入为红色,则此处的结束语句为:“header content goes here”,这是正确的。
如果我问的是愚蠢的问题,请原谅我,因为我是 PHP 新手,我不知道在 switch 案例中使用函数作为变量是否可以。
test1.php
<?php
function header2() { ?>
header content goes here
<?php }
$good =header2();
$Input2 = $_POST['input'];
switch ($Input2) {
case "red":
echo $good;
break;
case "blue":
echo "Your favorite color is blue!";
break;
case "green":
echo "Your favorite color is green!";
break;
default:
echo "Your favorite color is neither red, blue, nor green!";
}
?>
main.js
$('[id=stringone]').click(function(){
var string =$('[id=stringotherone]').val();
$.post('test1.php',{input: string}, function(data){
$('[id=stringotherthanone]').text(data);
});
});
test.php
<! doctype html>
<html lang="en">
<head>
<link rel="stylesheet" href="css/hwcb.css">
</head>
<body>
<input type="button" value="Go" id="stringone">
<input type="text" id="stringotherone"/>
<p><div id="stringotherthanone"></div></p>
<script src="jquery.js"></script>
<script src="js/css.js"></script>
<script src="main.js"></script>
</body>
</html>
【问题讨论】:
标签: php function switch-statement return