如何将target =“_blank”在jQuery中? [英] How to put target="_blank" in jQuery?
本文介绍了如何将target =“_blank”在jQuery中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试了许多变体,将 target =_ blank
与jQuery链接,但我无法使其工作。
I tried many variations to put target="_blank"
in links with jQuery, but I can't get it to work.
这是我的代码:
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"))
);
}
}
});
我该怎么做?
推荐答案
信息太多!这应该可以正常工作:
Too much information! This should work fine:
$("a").attr("target","_blank");
看到这里的例子 http://jsbin.com/evexi/edit 。它的工作完美。
See the example here http://jsbin.com/evexi/edit. It works perfectly.
这篇关于如何将target =“_blank”在jQuery中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文