使用无序列表创建表单?

时间:2010-07-31 19:39:59

标签: html forms css html-lists

这是对我之前的问题的继续,这个问题与之前的一些SO问题相似。虽然所有相关问题的答案让我想到了这一点:

我们应该使用无序列表来创建表单吗?虽然我的评论不一。

特定博客http://green-beast.com/blog/?p=259表示使用表单的无序列表是不正确的。我对开发人员的问题是对此声明发表评论吗?

2 个答案:

答案 0 :(得分:4)

  

HTML为作者提供了几种指定信息列表的机制。所有列表必须   包含一个或多个列表元素。列表可能包含:无序信息,已订购   信息和定义。 (来自http://www.w3.org/TR/html4/struct/lists.html#edef-UL

我认为列表是HTML中最重要的元素:从语义上讲,有很多对象是纯列表。使用uldlform中的输入字段和标签进行分组也是一种很好的做法。

有人会使用段落标记表单:

<form action="" method="post">
    <fieldset>
        <p>
            <label>
                Full Name: 
                <input type="text" name="name" />
            </label>
        </p>
        <p>
            <label>
                Password: 
                <input type="password" name="password" />
            </label>
        </p>
    </fieldset>
    <fieldset>
        <p>
            <label>
                Occupation: 
                <input type="text" name="occupation" />
            </label>
        </p>
        <p>
            <label>
                Location: 
                <input type="text" name="location" />
            </label>
        </p>
    </fieldset>
    <p>
        <input type="submit" value="Submit" />
    </p>
</form>

有人会使用列表标记它(在我看来这看起来非常有机):

<form action="" method="post">
    <fieldset>
        <dl>
            <dt><label for="name">Full Name:</label></dt>
            <dd><input id="name" type="text" name="name" /></dd>
            <!-- <dd class="error">Some errors/validation warnings</dd> -->

            <dt><label for="password">Password:</label></dt>
            <dd><input id="password" type="password" name="password" /></dd>
            <!-- <dd class="note">Some notes about the field above</dd> -->
        </dl>
    </fieldset>
    <fieldset>
        <dl>
            <dt><label for="occupation">Occupation:</label></dt>
            <dd><input id="occupation" type="text" name="occupation" /></dd>

            <dt><label for="location">Location:</label></dt>
            <dd><input id="location" type="text" name="location" /></dd>
        </dl>
    </fieldset>
    <p>
        <input type="submit" value="Submit" />
    </p>
</form>

表单列表(字段列表,分组数据),因为它们具有统一且重复的结构:

INPUT_1
INPUT_2
...
INPUT_N

答案 1 :(得分:0)

您可以将表单粘贴在段落,表格,列表,定义列表或一系列复杂的跨度和div中,但最重要的是,您的表单是否正常运行且人们可以使用它。

花时间在tabindex and usability而不是担心W3C工作组或某人博客定义的“语法正确的HTML编写方式”。