jQuery:选择非空的数据属性? [英] jQuery: Select data attributes that aren't empty?

查看:131
本文介绍了jQuery:选择非空的数据属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试选择所有具有 data-go-to 属性且非空的元素。

I'm trying to select all elements that have a data-go-to attribute that is not empty.

我已经尝试 $('[data-go-to!=]')但奇怪的是它似乎在选择页面上的每个元素如果我这样做。

I've tried $('[data-go-to!=""]') but oddly enough it seems to be selecting every single element on the page if I do that.

推荐答案

试试

$(':not([data-go-to=""])')

更新:

为了不让任何人误入歧途,这个答案适用于旧版本的jQuery但不具备面向未来的能力。由于@gmo和@ siva的答案似乎都适用于以后的版本,我推迟(并鼓励你提出)他们的答案....当然希望你有一个美好的一天。

For the sake of not leading anyone astray, this answer will work in older versions of jQuery but is not future-proof. Since @gmo and @siva's answers both seem to be working with later versions I defer to (and encourage you to upvote) their answers....and of course hope you have a fantastic day.

这篇关于jQuery:选择非空的数据属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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