【发布时间】:2015-09-22 03:16:13
【问题描述】:
这是我的代码:
<?php
$firstQuestion == true;
if($firstQuestion == true) {
?>
<script>alert('firstQuestion is true');</script>
<h1>1. YES OR NO?</h1>
<form method="post" action="index.php">
<input type="radio" name="1" id="yes" class="yes" value="yes" checked="checked"><label for="yes">Yes</label><br>
<input type="radio" name="1" id="no" class="no" value="no"><label for="no">No</label><br>
<input type="submit" name="submit">
</form> <?php
}
if(isset($_POST ['submit'])) {
$firstQuestion == false;
if($_POST ['1'] === 'yes') {
echo 'Input was recieved as yes';
} else {
echo 'Input was recieved as no';
}
}
?>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
由于某种原因,第一个表单没有出现。 我可以将表单放在正文中,然后使用 javascript 使其消失,但这是一个更大项目的开始,它将根据答案回显更多问题,因此 javascript 方法效率低得多。
【问题讨论】:
-
应该在body标签里面
-
嗯,是的,它完全在 DOM 之外,所以它不应该渲染。我建议您阅读一些有关 HTML、DOM、Javascript、AJAX 和 PHP 的知识。至少是基础知识,这样您就可以了解每个部分的作用。
标签: php html input radio-button