简体   繁体   English

“此时元素div上不允许使用属性名称”

[英]“Attribute name not allowed on element div at this point”

I am getting a W3V validator error that I can't understand: 我收到一个W3V验证器错误,我无法理解:

Line 31, Column 61: Attribute name not allowed on element div at this point. 第31行,第61列:此时元素div上不允许使用属性name

That is this row: 这就是这一行:

<div name="message" class="jGrowl bottom-right errorGrowl"></div>

Full HTML: 完整的HTML:

<!DOCTYPE html>
<html>
    <head>
        <title>jGrowl</title>

        <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>     
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js"></script>

        <script type="text/javascript" src="data/awo-jgrowl.js"></script>
        <script type="text/javascript" src="data/shortcut.js"></script>

        <link rel="stylesheet" type="text/css" href="data/awo-jgrowl.css">

        <script type="text/javascript">
            $(document).ready(function() {
                $('div[name=message]').awomsg('Input message', {sticky: true});
            });

            shortcut.add("m",function() {
                $('div[name=message]').awomsg('Input message', {sticky: true});
            });

            shortcut.add("h",function() {
                alert('ur doin it wrong');
            });
        </script>

    </head>
    <body>
        <div name="message" class="jGrowl bottom-right errorGrowl"></div>
    </body> 
</html>

I found some entry from: 我找到了一些来自:

Markup Validation Error: "Attribute name not allowed on element at this point" error #HTML5 标记验证错误:“此时元素上不允许使用属性名称”错误#HTML5

Just in case you intend to define a custom attribute, you have to prepend the attribute with " data- ". 如果您打算定义自定义属性,则必须在属性前添加“ data- ”。

So in this case, name would be: data-name="" . 所以在这种情况下,名称将是: data-name=""

And you can reference it by 'div[data-name="value"]' . 你可以用'div[data-name="value"]'来引用它。

The error message seems pretty self explanatory. 错误消息似乎很自我解释。 You cannot have a name attribute on a div tag. 您不能在div标签上使用name属性。 So your code could look like this: 所以你的代码看起来像这样:

<div id="message" class="jGrowl bottom-right errorGrowl"></div>

and then use id selectors: 然后使用id选择器:

$('div#message')...

There is no name attribute for div elements. div元素没有name属性。

If you want to uniquely identify one, then use id . 如果要唯一标识一个,请使用id

If you want to mark one as a member of a group, then use class . 如果要将one标记为组的成员,请使用class

The only place you can use a name attribute (that hasn't been deprecated) is on form controls ( input , select , textarea and button ). 您可以使用name属性(尚未弃用)的唯一位置是表单控件( inputselecttextareabutton )。

This is a late response, but since this page just came up in a search: 这是一个迟到的回复,但由于此页面刚出现在搜索中:

Since the name attribute is not permitted on certain elements and has special significance in forms which you may not want, but any attribute name starting with "data-" is acceptable to use for purposes of your own, I recommend using the "data-name" attribute, like this: 由于某些元素上不允许使用name属性,并且在您可能不需要的表单中具有特殊意义,但任何以“data-”开头的属性名称都可以用于您自己的目的,我建议使用“数据名称” “属性,像这样:

<div data-name="message" class="jGrowl bottom-right errorGrowl"></div>

You can then write: 然后你可以写:

$('[data-name="message"]').text("Here is a new message!");

And otherwise manipulate the div via jQuery. 否则通过jQuery操纵div。

The use of data attributes has the virtue that it is unlikely to conflict with what your frontend designers may be doing with IDs and class names for CSS purposes. 数据属性的使用具有以下优点:它不太可能与您的前端设计人员为CSS目的使用ID和类名进行冲突。

In our office we have an understanding that IDs and classes are reserved for CSS, and JavaScript developers should leave them alone. 在我们的办公室,我们了解到ID和类是为CSS保留的,JavaScript开发人员应该不管他们。 Conversely, frontend designers are welcome to change the ID, classes or even element type of most things, provided that they don't mess with the data attributes. 相反,前端设计人员可以更改大多数事物的ID,类甚至元素类型,只要它们不会混淆数据属性。

The name attribute is not part of the specification for DIV elements. name属性不是DIV元素规范的一部分。 name is, generally speaking, only valid on form elements. 一般来说, name仅对表单元素有效。

See: http://www.w3schools.com/tags/tag_div.asp 请参阅: http//www.w3schools.com/tags/tag_div.asp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM