【问题标题】:I am trying to validate this form page xhtml and it will not validate我正在尝试验证此表单页面 xhtml,但它不会验证
【发布时间】:2011-08-04 22:58:36
【问题描述】:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>The Magic Genie</title>
<link href="java-game.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="java-game.js"></script>
</head>

<body class="oneColFixCtr">

<div id="container">
  <div id="mainContent">
    <h1>Ask Your Magic Genie </h1>

<form>
Your question: <input type="text" name="question" size="40">
<input type="button" name="ask" value="Ask the Genie" onClick="if (this.form.question.value!='') this.form.answer.value = genie();">
<br />
<br />
Your magic genie says:  <input type="text" name="answer" size="50">
</form></p>


</div>
</body>
</html>

【问题讨论】:

  • 那甚至不是连贯的代码;您没有关闭输入标签,并且在“onClick”属性中有随机标签,在 XHTML 中实际上应该是“onclick”。你还有一个空类型的输入标签,这也没有意义。

标签: html xhtml xhtml-1.0-strict html-validation


【解决方案1】:

你的问题是你没有 doctype、html、head 或 body 标签。

【讨论】:

    【解决方案2】:

    您的页面将无法验证,仅仅是因为您错误地嵌套/关闭标签,并且某些标签没有正确的属性。

    【讨论】:

    • 注意:不要费心编辑这个问题来让它突出显示。根本问题是缺乏基本的连贯性。
    【解决方案3】:

    首先你在谈论 xhtml 并添加了 xhtml-1.0-strict 标签,但你的标题状态:&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;

    我一生中从未见过&lt;body class="oneColFixCtr"&gt; 课程被添加到&lt;body&gt;。您可以通过 body {background: red;} 在 CSS 中操作 &lt;body&gt;

    缺少 1x &lt;div&gt; 标签!有 1 个额外的 &lt;/p&gt;。很多标签不是以/ 结尾的。 &lt;form&gt; 缺少方法和操作参数!

    另外,如果你想要 100% 完美的验证,你不能使用onclick=""。我在你的脚本中添加了 jQuery。

    现场示例:http://kopli.pri.ee/stackoverflow/5653786.phpclick here 进行验证)

    完整版代码:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>I am trying to validate this form page xhtml and it will not validate - Kalle H. Väravas</title>
        <link href="java-game.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
        <script type="text/javascript" src="java-game.js"></script>
    </head>
    <body>
        <div id="container">
            <div id="mainContent">
                <h1>Ask Your Magic Genie </h1>
                <form method="post" action="">
                    Your question: <input type="text" name="question" size="40" />
                    <input type="button" name="ask" value="Ask the Genie" /><br />
                    <br />
                    Your magic genie says:  <input type="text" name="answer" size="50" />
                </form>
            </div>
        </div>
        <script type="text/javascript">
            $('input[name=ask]').click(function () {
                if ($(this).form.question.value!='') {
                    $(this).form.answer.value = genie();
                }
            });
        </script>
    </body>
    </html>
    

    【讨论】:

      猜你喜欢
      • 2016-11-05
      • 2014-07-04
      • 1970-01-01
      • 2013-02-21
      • 2014-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-02
      相关资源
      最近更新 更多