我尝试了很多变化,把target="_blank"
与jQuery链接,但我无法让它工作。如何在jQuery中放置target =“_ blank”?
这里是我的代码:
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 [href^='http']”)。attr('target','_ blank');' – 2013-01-09 17:00:33
谢谢你的队友,帮帮我 – DextrousDave 2013-04-02 09:16:50
疯狂有用,谢谢! – 2013-11-28 04:30:17