jquery循环和比较值

lgt*_*lgt 2 jquery

是否可以使用jqueries这个形式的每个循环来解散超链接?

 $(document).ready(function() {
    var toExclude =['http://www.google.com', 'http://example'];
    $.each(toExclude, function(key, value) {

    $("a[href='+value+']").replaceWith(function(){
        var matches = value.match(/^https?\:\/\/([^\/?#]+)(?:[\/?#]|$)/i);
        var domain = matches && matches[1];
        return domain;
                });
            });
        });
Run Code Online (Sandbox Code Playgroud)

Dar*_*rov 5

$("a[href='+value+']")
Run Code Online (Sandbox Code Playgroud)

应该:

$("a[href='"+value+"']")
Run Code Online (Sandbox Code Playgroud)

您也可能只想更改href属性=>使用.attr方法:

$("a[href='"+value+"']").attr("href", function() {
    // do your replace and return the new value of the href
    ...
});
Run Code Online (Sandbox Code Playgroud)