2010-08-20 5 views

Répondre

7

Vous pouvez utiliser un attribute-contains selector, comme ceci:

$("a[href*='?iframe'], a[href*='&iframe']") 

Ce trouverait aussi des choses comme ceci:

<a href="http://www.example.com?sortby=awesomeness&iframe"> 
1

si vous utilisez jQuery, il serait être

var iframeLinks = $("a[href*='iframe']") 
+0

Gardez à l'esprit ce trouverait aussi * partout * dans le lien , par exemple 'www.iframe.com' serait également correspondre :) –

0

si la recherche est très spécifique, vous pouvez créer un nouveau sélecteur:

(function($) { 

    $.fn.tagName = function() { 
    return this.get(0).tagName.toLowerCase(); 
    } 

    $.expr[':'].inHRef = function(obj, index, meta, stack){ 

    if ($(obj).tagName() != 'a') 
     return false; 

    var afi = $(obj).attr('href').split('?'), sfi, txt = meta[3]; 

    if (afi.length == 1) 
     return false; 

    sfi = afi[1]; 

    // Regular Expression 

    var rgCI = '\\'+sfi+'\\gi'; 

    // case-insensitive 
    return (rgCI.match(txt)); 

    var rgCS = '\\'+sfi+'\\g'; 

    // case-sensitive 
    //return (rgCS.match(txt)); 

    // IndexOf 

    // case-insensitive 
    //return (sfi.toLowerCase().indexOf(txt.toLowerCase()) > -1); 

    // case-sensitive 
    //return (sfi.indexOf(txt) > -1); 

}; 

})(jQuery); 

$(function() { 

    $('a:inHRef(iframe)').css('background-color', '#aaaaa0'); 

});​ 

example

example update

example end update

+0

Cela aurait également les mêmes problèmes contient :) http://jsfiddle.net/nick_craver/qzpbd/3/ –

+0

si, juste ce qui était en cours de mise à jour http: // jsfiddle .net/qzpbd/4 / –

Questions connexes