For example, I wa开发者_StackOverflow社区nt to match all links that have the iframe
param. Thus, it would match:
<a href="http://www.example.com?iframe">
<a href="http://www.example.com?iframe=1">
<a href="http://www.example.com?iframe&sortby=awesomeness">
You could use an attribute-contains selector, like this:
$("a[href*='?iframe'], a[href*='&iframe']")
This would also find things like this:
<a href="http://www.example.com?sortby=awesomeness&iframe">
if you use jQuery it would be
var iframeLinks = $("a[href*='iframe']")
if the search is very specific, you can create a new selector:
(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
精彩评论