Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 此时元素li上不允许使用属性类别_Jquery_Html_Filtering_Validation - Fatal编程技术网

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

Jquery 此时元素li上不允许使用属性类别,jquery,html,filtering,validation,Jquery,Html,Filtering,Validation,我从中发现了这一点,这非常简洁,但是分类过滤器给出了以下错误: Attribute category not allowed on element li at this point. 以下是过滤器标记: <ul> <!-- change the "cat-1", "cat-2", "cat-3" with your "Categories ID" --> <li class="cat-active" category="prod-cnt">A

我从中发现了这一点,这非常简洁,但是分类过滤器给出了以下错误:

Attribute category not allowed on element li at this point.
以下是过滤器标记:

<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>
    所有 第一类 第二类 第三类

是否可以修复此问题或使用其他属性?多谢各位

通常,自定义属性(W3C未定义的属性)以数据作为前缀-


因此,请尝试:data category=“”

通常自定义属性(W3C未定义的属性)以数据为前缀-


因此,请尝试:data category=“”

遵循@El Guapo的答案,并在jQuery中更改这一行

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

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


按照@El Guapo的答案,在jQuery中更改这一行

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

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


请解释为什么这是必要的。如果他将属性从“类别”更改为“数据类别”,他必须更改查找新属性的方式。他也可以查找attr('data-category'),但是jQuery有一个内置的for.data,他不“必须”这样做,而且因为他处理的是字符串,所以使用.data代替.attr没有任何好处。我不同意,在你的评论中,你说“他必须改变查找新属性的方式”这是不正确的。这是正确的,因为他必须更改属性名。让我们不要陷入语义的泥潭。:-)请解释为什么这是必要的。如果他将属性从“类别”更改为“数据类别”,他必须更改查找新属性的方式。他也可以查找attr('data-category'),但是jQuery有一个内置的for.data,他不“必须”这样做,而且因为他处理的是字符串,所以使用.data代替.attr没有任何好处。我不同意,在你的评论中,你说“他必须改变查找新属性的方式”这是不正确的。这是正确的,因为他必须更改属性名。让我们不要陷入语义的泥潭。:-)