【问题标题】:PHP and HTML Radio errorPHP 和 HTML Radio 错误
【发布时间】: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


【解决方案1】:

您需要将 php 标签中的全部内容放入 body 标签中(&lt;body&gt; &lt;?php $firstQuestion = true; //and so on... ?&gt; &lt;/body&gt;)。所以浏览器可以渲染这个DOM结构。这是编写 HTML 代码时最重要的事情。

希望这会有所帮助!

【讨论】:

  • 不起作用...Here's 我现在拥有的。即使你把它放在身体里也没有任何显示。
  • 不知何故你没有输出一些东西。我的网络浏览器返回以下内容:&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;/head&gt; &lt;body&gt; &lt;/body&gt; &lt;/html&gt; 你能在这里发布你的代码吗?
  • 好吧,我的只是不输出表格。它确实输出&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;/head&gt; &lt;body&gt; &lt;/body&gt; &lt;/html&gt;。另外,here's 是我正在尝试的链接。
  • 问题中的php代码是php代码。我只是将它移入体内。
  • pastebin.com/910pVaJv 不能使用“==”运算符为变量赋值,必须使用“=”运算符。
猜你喜欢
  • 2014-06-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-17
  • 2015-09-13
  • 2012-07-11
  • 2023-03-17
相关资源
最近更新 更多