“此时元素 div 上不允许有属性名称”
我收到一个我无法理解的 W3V 验证器错误:
第 31 行,第 61 列:此时元素
div
上不允许使用属性name
。
就是这一行:
<div name="message" class="jGrowl bottom-right errorGrowl"></div>
完整的 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 am getting a W3V validator error that I can't understand:
Line 31, Column 61: Attribute
name
not allowed on elementdiv
at this point.
That is this row:
<div name="message" class="jGrowl bottom-right errorGrowl"></div>
Full 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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我发现了一些条目:
标记验证错误:“此时元素上不允许属性名称”错误 #HTML5
如果您打算定义自定义属性,则必须在该属性前面添加“
data-”。
因此在本例中,名称为:
data-name=""
。您可以通过
'div[data-name="value"]'
引用它。I found some entry from:
Markup Validation Error: "Attribute name not allowed on element at this point" error #HTML5
Just in case you intend to define a custom attribute, you have to prepend the attribute with "
data-
".So in this case, name would be:
data-name=""
.And you can reference it by
'div[data-name="value"]'
.该错误消息似乎非常不言自明。
div
标记上不能有name
属性。所以你的代码可能如下所示:然后使用 id 选择器:
The error message seems pretty self explanatory. You cannot have a
name
attribute on adiv
tag. So your code could look like this:and then use id selectors:
div 元素没有
name
属性。如果您想唯一标识一个,请使用
id
。如果您想将一个标记为组的成员,请使用
class
。唯一可以使用
name
属性(尚未弃用)的地方是表单控件(input
、select
、文本区域
和按钮
)。There is no
name
attribute for div elements.If you want to uniquely identify one, then use
id
.If you want to mark one as a member of a group, then use
class
.The only place you can use a
name
attribute (that hasn't been deprecated) is on form controls (input
,select
,textarea
andbutton
).这是一个迟到的回复,但由于此页面刚刚在搜索中出现:
由于某些元素不允许使用 name 属性,并且在您可能不想要的表单中具有特殊意义,但任何以“data-”开头的属性名称都是如果您可以出于自己的目的使用,我建议使用“data-name”属性,如下所示:
然后您可以编写:
或者通过 jQuery 操作 div。
使用数据属性的优点是,它不太可能与前端设计人员为 CSS 目的而使用 ID 和类名所做的事情发生冲突。
在我们的办公室,我们知道 ID 和类是为 CSS 保留的,JavaScript 开发人员应该不要管它们。相反,前端设计者可以更改大多数事物的 ID、类甚至元素类型,只要他们不弄乱数据属性即可。
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:
You can then write:
And otherwise manipulate the div via jQuery.
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.
In our office we have an understanding that IDs and classes are reserved for CSS, and JavaScript developers should leave them alone. 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.
name
属性不是 DIV 元素规范的一部分。一般来说,name
仅在表单元素上有效。请参阅:http://www.w3schools.com/tags/tag_div.asp
The
name
attribute is not part of the specification for DIV elements.name
is, generally speaking, only valid on form elements.See: http://www.w3schools.com/tags/tag_div.asp