简体   繁体   English

此时,元素li上不允许使用属性类别

[英]Attribute category not allowed on element li at this point

I came across this Grid/List layout demo from this page , which is pretty neat, but the validator gives this error for the category filter: 我从此页面偶然看到了这个Grid / List布局演示 ,这很简洁,但是验证器为类别过滤给出了此错误:

Attribute category not allowed on element li at this point.

Here's the filter markup: 这是过滤器标记:

<ul>
   <!-- change the "cat-1", "cat-2", "cat-3" with your "Categories ID" -->
     <li class="cat-active" category="prod-cnt">All</li>
     <li class="" category="cat-1">Category 1</li>
     <li class="" category="cat-2">Category 2</li>
     <li class="" category="cat-3">Category 3</li>
</ul>

Is it possible to fix this or use another attribute? 是否可以解决此问题或使用其他属性? Thank you. 谢谢。

Typically custom attributes (those not defined by the W3C) are prefixed with data- 通常,自定义属性(W3C未定义的属性)的前缀是data-

so try: data-category="" 因此,请尝试:data-category =“”

Follow @El Guapo's answer and change this line in the jQuery 跟随@El Guapo的答案并在jQuery中更改此行

var CategoryID = $(this).attr('category');

change to: 改成:

var CategoryID = $(this).data('category');

or: 要么:

var CategoryID = $(this).attr('data-category');

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

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