Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/461.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
Javascript 如何检查具有.Attr的元素是否具有特定的类?_Javascript_Jquery - Fatal编程技术网

Javascript 如何检查具有.Attr的元素是否具有特定的类?

Javascript 如何检查具有.Attr的元素是否具有特定的类?,javascript,jquery,Javascript,Jquery,这是HTML结构: <div data-step="1"></div> <div data-step"2" class="active"></div> 用于获取具有特定属性值的元素。方法只需设置属性值并返回jQuery元素对象 if($("div[data-step='2']").hasClass("active")) // or simply combine the class with selector and // check exist

这是HTML结构:

<div data-step="1"></div>
<div data-step"2" class="active"></div>
用于获取具有特定属性值的元素。方法只需设置属性值并返回jQuery元素对象

if($("div[data-step='2']").hasClass("active"))

// or simply combine the class with selector and
// check existance simply by checking its length
if($("div[data-step='2'].active").length)

$(“div”).attr(“数据步骤”,“2”)
设置value@LGSon我知道这是错误的,只是一个更口头的例子,试图更好地解释我在看什么for@rob.m:很乐意帮忙:)
if($("div[data-step='2']").hasClass("active"))

// or simply combine the class with selector and
// check existance simply by checking its length
if($("div[data-step='2'].active").length)