【问题标题】:Text Input in HTML Form won't show upHTML 表单中的文本输入不会显示
【发布时间】:2015-08-25 12:48:50
【问题描述】:

我正在开发一个基于文本的在线游戏(非常不完整),我主要使用 PHP。在我的 HTML 中,我有一个用于游戏命令的表单(文本输入),但它不会显示出来。这是我的 HTML:

<div class="container">
    <div class="main">
    <?php
        include_once 'game.php';
    ?>
    </div>
    <FORM NAME="form1" METHOD="POST" ACTION="">
        <INPUT TYPE="TEXT" VALUE="" name="input"
            style="width: 600; position: absolute; bottom: 0; z-index: 2;">
        </INPUT>
    </FORM>
    <?php
        $input = $_POST["input"];
    ?>
</div>

所以实际上是 FORM 和 INPUT 把我搞砸了,因为它没有出现。如果有帮助,我也将它作为我的 CSS:

.main {
    width: 600px;
    height: 400px;
    background-color: white;
    border: 1px solid black;
    position: absolute;
    top:0;
    left: 0;
    right: 0;
    z-index: 1;
}

.container {
    width: 602px;
    height: 500px;
    background-color: white;
    border: 1px solid blue;
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 0;
    margin: 0 auto;
}

当然,我有我的game.php,但我觉得这不是问题所在。

任何帮助将不胜感激。

编辑:根据人们的回答,它可能是 PHP。这是game.php文件的完整代码,我不知道哪里出了问题。

<?php
include_once 'index.php';
$World = simplexml_load_file("gameworld.xml");
$CurrentPos = 0;
$Done = 0;
print "<br>";
printplace();
function printplace() {
    GLOBAL $World, $CurrentPos;
    $Room = $World->ROOM[$CurrentPos];
    $Name = $Room->NAME;
    $Desc = wordwrap((string)$Room->DESC);
    print "$Name<br>";
    print str_repeat('-', strlen($Name));
    print "<br>$Desc<br>";
    if ((string)$Room->NORTH != '-') {
        $index = (int)$Room->NORTH;
        print "North: {$World->ROOM[$index]->NAME}<br>";
    }
    if ((string)$Room->SOUTH != '-') {
        $index = (int)$Room->SOUTH;
        print "South: {$World->ROOM[$index]->NAME}<br>";
    }
    if ((string)$World->ROOM[$CurrentPos]->WEST != '-') {
        $index = (int)$Room->WEST;
        print "West: {$World->ROOM[$index]->NAME}<br>";
    }
    if ((string)$World->ROOM[$CurrentPos]->EAST != '-') {
        $index = (int)$Room->EAST;
        print "East: {$World->ROOM[$index]->NAME}<br>";
    }
    print "<br>";
}

while (!$Done) {
    print "<br>"; // add another line break after the user input

    $input = split(' ', $input);

    switch(trim($input[0])) {
        case 'north':
            if ((string)$World->ROOM[$CurrentPos]->NORTH != '-') {
                $CurrentPos = (int)$World->ROOM[$CurrentPos]->NORTH;
                printplace() ;
            } else {
                print "You cannot go north!<br>";
            }
            break;
        case 'south':
            if ((string)$World->ROOM[$CurrentPos]->SOUTH != '-') {
                $CurrentPos = (int)$World->ROOM[$CurrentPos]->SOUTH;
                printplace() ;
            } else {
                print "You cannot go south!<br>";
            }
            break;
        case 'west':
            if ((string)$World->ROOM[$CurrentPos]->WEST != '-') {
                $CurrentPos = (int)$World->ROOM[$CurrentPos]->WEST;
                printplace() ;
            } else {
                print "You cannot go west!<br>";
            }
            break;
        case 'east':
            if ((string)$World->ROOM[$CurrentPos]->EAST != '-') {
                $CurrentPos = (int)$World->ROOM[$CurrentPos]->EAST;
                printplace() ;
            } else {
                print "You cannot go east!<br>";
            }
            break;
        case 'look':
            printplace() ;
            break;
        case 'quit':
            $Done = 1;
            break;
    }
}

print "<br>Thanks for playing!<br>";
?>

真的,它只是http://www.hackingwithphp.com/21/4/2/text-game-v1 的一个分支 我试图移植到浏览器,但它失败了......

【问题讨论】:

  • 如果您删除include('game.php'),问题会消失吗?
  • 当我加载你的网页时,它会占用我的 CPU。
  • 是的,我也是这么想的。不过我不确定。上次试的时候,没有结果。
  • 嗯。我想知道。那么有些不对劲......好吧,我的意思是,不,但让我检查一下。
  • 是的。我注释掉了 include('game.php');一切正常。我更新了没有game.php的网站。

标签: php html css forms input


【解决方案1】:

它在 Chrome 和 Firefox 中显示良好。见下文。

.main {
  width: 600px;
  height: 400px;
  background-color: white;
  border: 1px solid black;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1;
}
.container {
  width: 602px;
  height: 500px;
  background-color: white;
  border: 1px solid blue;
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 0;
  margin: 0 auto;
}
<div class="container">
  <div class="main">
  </div>
  <FORM NAME="form1" METHOD="POST" ACTION="">
    <INPUT TYPE="TEXT" VALUE="" name="input" style="width: 600; position: absolute; bottom: 0; z-index: 2;">
    </INPUT>
  </FORM>
</div>

【讨论】:

  • 有趣。那可能是php?查看 urbanadventure.dumpong.tk。那是游戏的实际站点......它在那里不起作用。
  • 那个页面没有完成加载,我的浏览器完全崩溃了。两次。
  • 它有效,但只有在我注释掉 include('game.php'); 之后。所以这可能是PHP的问题......
猜你喜欢
  • 1970-01-01
  • 2015-01-23
  • 2012-06-28
  • 2020-12-13
  • 2020-03-10
  • 1970-01-01
  • 2012-06-14
  • 2011-08-23
  • 2019-04-26
相关资源
最近更新 更多