PHP代码不显示像相同的HTML代码

时间:2013-11-11 09:33:09

标签: php jquery html

我有一个网站,我上传了index.html,它完全由HTML代码组成(没有PHP)。

我将此代码复制到PHP文件index.php,此外我将标题分成单独的php文件。当我清理新的index.php时,我只是使用include()来包含标题,如下所示:

<? include("TopNote.php"); ?>

因此index.htmlindex.php之间的区别在于HTML代码直接位于index.html和PHP文件中,它包含在单独的PHP文件中。

现在index.php文件提供了一个奇怪的按钮,index.html显示了我希望它显示的所有内容。

index.html

<!doctype html>
<html lang="us">
<head>
  <meta charset="utf-8">
  <link rel="stylesheet" type="text/css" href="web/style.css">
  <link href="css/smoothness/jquery-ui-1.10.3.custom.css" rel="stylesheet">
  <style>
    .ui-menu { position: absolute; width: 100px; }
  </style>
  <script src="js/jquery-1.9.1.js"></script>
  <script src="js/jquery-ui-1.10.3.custom.js"></script>
  <script>
    $(function() {
      $( "#menu" ).buttonset();
      $( "#regdialog" ).dialog();
      $( "#buttonregister" ).click(function() {
        $( "#regdialog" ).dialog( "open" );
      });
    });
  </script>
</head>
<body bgcolor="#aaaaaa">
  <img src="example.lorg" alt="" style="padding-left:20px" />
  <div align="right" style="padding-right:20px">
    <div>
      <button id="StaffLogin">Staff Login</button>

      <button id="select">Select an action</button>
    </div>
    <ul>
      <li><a href="#">Log Out</a></li>
      <li id="buttonregister"><a href="#">Register</a></li>
    </ul>
  </div>  
  <form style="margin-top: 1em;">  
    <div id="menu" align="center">
      <input type="radio" id="buttonhome" name="radio" checked="checked"><label for="buttonhome">Home</label>
      <input type="radio" id="buttonforums" name="radio"><label for="buttonforums"><a href="http://example.org">Forums</a></label>
      <input type="radio" id="buttonapply" name="radio"><label for="buttonapply"><a class='fb_iframe' href="http://example.org">Apply</a></label>
      <input type="radio" id="buttonabout" name="radio"><label for="buttonabout">About Us</label>
      <input type="radio" id="select" name="radio">
    </div>
  </form>



  <br />
  <div class="ui-widget">
    <div class="ui-state-error ui-corner-all" style="padding: 0 .7em;">
      <p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>
        <strong>Alert:</strong> The Site Is No Where Near Completed, Please go to our <a href="http://example.org/">Forums</a>
      </p>
    </div>
  </div>
  <!-- POP UP -->
  <div id="regdialog" title="Register">
    <form action="#" method="post">
      <div class="ui-widget">
        <div class="ui-state-error ui-corner-all" style="padding: 0 .7em;">
          <p>
            <span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>
            Registrations are not working!
          </p>
        </div>
      </div>
      <h5>Username:</h5>
      <input type="text" name="reg_name">
      <h5>Password:</h5>
      <input type="password" name="reg_pass">
      <h5>Confirm Password:</h5>
      <input type="password" name="reg_pass_conf">
      <input type="submit">
    </form>
  </div>
</body>
</html> 

index.php

<!doctype html>
<html lang="us">
<head>
  <meta charset="utf-8">
  <link rel="stylesheet" type="text/css" href="web/style.css">
  <link href="css/smoothness/jquery-ui-1.10.3.custom.css" rel="stylesheet">
  <script src="js/jquery-1.9.1.js"></script>
  <script src="js/jquery-ui-1.10.3.custom.js"></script>
</head>
<body bgcolor="#aaaaaa">
  <? include("TopNote.php"); ?>
</body>
</html>

topnote.php

<!doctype html>
<html lang="us">
<head>
  <meta charset="utf-8">
  <link rel="stylesheet" type="text/css" href="web/style.css">
  <link href="css/smoothness/jquery-ui-1.10.3.custom.css" rel="stylesheet">
  <style>
    .ui-menu { position: absolute; width: 100px; }
  </style>
  <script src="js/jquery-1.9.1.js"></script>
  <script src="js/jquery-ui-1.10.3.custom.js"></script>
  <script>
    $(function() {
      $( "#menu" ).buttonset();
      $( "#regdialog" ).dialog();
      $( "#buttonregister" ).click(function() {
        $( "#regdialog" ).dialog( "open" );
      });
    });
  </script>
</head>
<body bgcolor="#aaaaaa">
  <img src="example.lorg" alt="" style="padding-left:20px" />
  <div align="right" style="padding-right:20px">
    <div>
      <button id="StaffLogin">Staff Login</button>

      <button id="select">Select an action</button>
    </div>
    <ul>
      <li><a href="#">Log Out</a></li>
      <li id="buttonregister"><a href="#">Register</a></li>
    </ul>
  </div>  
  <form style="margin-top: 1em;">  
    <div id="menu" align="center">
      <input type="radio" id="buttonhome" name="radio" checked="checked"><label for="buttonhome">Home</label>
      <input type="radio" id="buttonforums" name="radio"><label for="buttonforums"><a href="http://example.org">Forums</a></label>
      <input type="radio" id="buttonapply" name="radio"><label for="buttonapply"><a class='fb_iframe' href="http://example.org">Apply</a></label>
      <input type="radio" id="buttonabout" name="radio"><label for="buttonabout">About Us</label>
      <input type="radio" id="select" name="radio">
    </div>
  </form>



  <br />
  <div class="ui-widget">
    <div class="ui-state-error ui-corner-all" style="padding: 0 .7em;">
      <p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>
        <strong>Alert:</strong> The Site Is No Where Near Completed, Please go to our <a href="http://example.org/">Forums</a>
      </p>
    </div>
  </div>
  <!-- POP UP -->
  <div id="regdialog" title="Register">
    <form action="#" method="post">
      <div class="ui-widget">
        <div class="ui-state-error ui-corner-all" style="padding: 0 .7em;">
          <p>
            <span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>
            Registrations are not working!
          </p>
        </div>
      </div>
      <h5>Username:</h5>
      <input type="text" name="reg_name">
      <h5>Password:</h5>
      <input type="password" name="reg_pass">
      <h5>Confirm Password:</h5>
      <input type="password" name="reg_pass_conf">
      <input type="submit">
    </form>
  </div>
</body>
</html>

有什么区别,我该如何解决?

2 个答案:

答案 0 :(得分:3)

<html>标记内不能包含<body>标记。您的topnote.php不需要拥有doctype,head和所有内容。因为index.php已经定义了html,doctype,head,title等。

所以你的topnote.php应该只包含这些元素:

<img src="http://destiny-craft.com/img/Logo_Resized.png" alt="" style="padding-left:20px" />
<div align="right" style="padding-right:20px">
  <div>
    <button id="StaffLogin">Staff Login</button>

    <button id="select">Select an action</button>
  </div>
  <ul>
    <li><a href="#">Log Out</a></li>
    <li id="buttonregister"><a href="#">Register</a></li>
  </ul>
</div>  
<form style="margin-top: 1em;">  
   <div id="menu" align="center">
            <input type="radio" id="buttonhome" name="radio" checked="checked"><label for="buttonhome">Home</label>
            <input type="radio" id="buttonforums" name="radio"><label for="buttonforums"><a href="http://forums.destiny-craft.com">Forums</a></label>
            <input type="radio" id="buttonapply" name="radio"><label for="buttonapply"><a class='fb_iframe' href="http://destiny-craft.coffeecup.com/forms/ApplyForm/">Apply</a></label>
        <input type="radio" id="buttonabout" name="radio"><label for="buttonabout">About Us</label>
        <input type="radio" id="select" name="radio">
    </div>
</form>



<br />
<div class="ui-widget">
    <div class="ui-state-error ui-corner-all" style="padding: 0 .7em;">
            <p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>
            <strong>Alert:</strong> The Site Is No Where Near Completed, Please go to our <a href="http://forums.destiny-craft.com/">Forums</a></p>
    </div>
</div>






<!-- POP UP -->
<div id="regdialog" title="Register">
<form action="#" method="post">
<div class="ui-widget">
    <div class="ui-state-error ui-corner-all" style="padding: 0 .7em;">
            <p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>
            Registrations are not working!</p>
    </div>
</div>
    <h5>Username:</h5>
    <input type="text" name="reg_name">
    <h5>Password:</h5>
    <input type="password" name="reg_pass">
    <h5>Confirm Password:</h5>
    <input type="password" name="reg_pass_conf">
    <input type="submit">
</form>
</div>

您可以将<script>的{​​{1}}标记中的<head>代码移至topnote.php的末尾。在结束topnote.php标记之前将它们放在正确的位置是有效且更好的做法。这确保了此时加载了所有DOM元素。

答案 1 :(得分:1)

topnote.php不应该有doctype,html和head,因为你已经在index.php中添加了

避免使用XML投标的短标记,使用如下

<?php include 'file.php'?>