删除所有target =" _blank"来自链接 [英] Remove all target="_blank" from links
本文介绍了删除所有target =" _blank"来自链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在搞乱jQuery并遇到了一个我似乎无法解决的问题。我知道有可能使用jQuery,但找不到合适的例子来解决问题。我有一个带有几个常规链接的页面,其中添加了属性/值 target =_ blank
。
I'm messing around with jQuery and ran in to a problem I can't seem to solve. I know it's possible with jQuery, but can't find a proper example to work off of. I have a page with a couple regular links with the attribute/value target="_blank"
added to it.
使用jQuery / JavaScript从页面上的每个链接中删除该值的最佳方法是什么?
What's the best approach with jQuery/JavaScript to remove that value from every link on the page?
推荐答案
这应该用jQuery做...
This should do it with jQuery...
$('a[target="_blank"]').removeAttr('target');
使用现代浏览器......
With a modern browser...
Array.from(document.querySelectorAll('a[target="_blank"]'))
.forEach(link => link.removeAttribute('target'));
使用较旧的浏览器,例如早期的IE浏览器......
With an older browser such as earlier IEs...
var links = document.links, i, length;
for (i = 0, length = links.length; i < length; i++) {
links[i].target == '_blank' && links[i].removeAttribute('target');
}
这篇关于删除所有target =" _blank"来自链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文