Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
例如,如果您有一个具有某个类的元素,class="selected"并且需要查看它是否具有某个 rel 值,那么该怎么做呢?
class="selected"
在基本逻辑中:
If('.selected' has 'rel=6'){ //action }
尝试这个;
If($(".selected").attr('rel') == '6'){ alert("ok"); }
最简单的形式是:
if ( $('.selected[rel=6]').length ){ //object found }
使用.is:
var $selected = $('.selected'); if ($selected.is('[rel=6]')) { ... }
... 或.filter:
var $selected = $('.selected'), $rel6 = $selected.filter('[rel=6]');
... jQuery 方法,取决于您的实际需要。