如何在jQuery中放置target =“_ blank”?

前端之家收集整理的这篇文章主要介绍了如何在jQuery中放置target =“_ blank”?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我尝试了许多变体,将target =“_ blank”放在与jQuery的链接中,但我无法使其工作。

这是我的代码

var thumbfile = "<?PHP echo $smit_iturl_v; ?>";
jQuery(document).ready(function () {
    var actualHost = jQuery.trim(jQuery.url.attr("host"));
    jQuery("a img").each(function (i) {

        if (jQuery.trim(jQuery.url.setUrl(jQuery(this).attr("src")).attr("host")) == actualHost &&      
            (jQuery.url.setUrl(jQuery(this).attr("src")).attr("path")).indexOf("wp-content") != -1 &&

            isImage(jQuery.url.setUrl(jQuery(this).attr("src")).attr("file"))) {

            var parentTag = jQuery(this).parent().get(0).tagName;
            parentTag = parentTag.toLowerCase();

            if (parentTag == "a" &&
            jQuery.url.setUrl(jQuery(this).parent().attr("href")).attr("host") == actualHost &&
            jQuery.url.setUrl(jQuery(this).parent().attr("href")).attr("path").indexOf("wp-content") != -1 &&
            isImage(jQuery(this).parent().attr("href"))) {

                var description = (jQuery(this).attr("alt") == "") ? jQuery(this).attr("title") : jQuery(this).attr("alt");
                jQuery(this).parent().attr("href",thumbfile +
                        "?title=" + jQuery(this).attr("title") +
                        "&description=" + description +
                        "&url=" + stripDomain(jQuery(this).parent().attr("href"))

                );
            }
        }
    });

我该怎么做?

解决方法

太多信息!这应该工作正常
$("a").attr("target","_blank");

看到这里的例子http://jsbin.com/evexi/edit.它的工作完美。

原文链接:https://www.f2er.com/jquery/182142.html

猜你在找的jQuery相关文章