检查数据属性值是否等于字符串 [英] Check if data attribute value equals a string

查看:139
本文介绍了检查数据属性值是否等于字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个元素,该元素在名为data-toggle-wmc<button class="navbar-toggle">元素上具有我的自定义属性,并且我正在尝试检查该属性值是否等于一个名为collapse的字符串值,到目前为止,它仍然无法正常工作.

I have an element that has a my custom attribute on a <button class="navbar-toggle"> element called data-toggle-wmc and I am trying to check whether the attribute value equals a string value called collapse somehow it has not worked so far.

我尝试了以下

if ($('button.navbar-toggle').attr('data-toggle-wmc') === 'collapse') {
     alert('123yes');
} 

我也尝试过

if ($('button.navbar-toggle').attr('data-toggle-wmc') == 'collapse') {
     alert('123yes');
}

我查看了这个问题,但不知何故该条件没有得到满足. /p>

I looked at this question but somehow the condition is not being fullfilled.

推荐答案

尝试:

if ($('button.navbar-toggle').data('toggle-wmc') === 'collapse') ...

这篇关于检查数据属性值是否等于字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆