Javascript HTML在元素上添加属性
当我写(很多)标记时,我没有写Javascript HTML在元素上添加属性,javascript,html,Javascript,Html,当我写(很多)标记时,我没有写'target=“\u blank”,因此没有链接指向其他窗口或标记 有没有办法将“target=''u blank'添加到使用JavaScript的所有链接中?前面的回答如下: 代码: /* here are two different ways to do this */ //using jquery: $(document).ready(function(){ $('#link_other a').attr('target', '_blank'); });
'target=“\u blank”
,因此没有链接指向其他窗口或标记
有没有办法将
“target=''u blank'
添加到使用JavaScript的所有链接中?前面的回答如下:
代码:
/* here are two different ways to do this */
//using jquery:
$(document).ready(function(){
$('#link_other a').attr('target', '_blank');
});
// not using jquery
window.onload = function(){
var anchors = document.getElementById('link_other').getElementsByTagName('a');
for (var i=0; i<anchors.length; i++){
anchors[i].setAttribute('target', '_blank');
}
}
// jquery is prettier. :-)
/*这里有两种不同的方法*/
//使用jquery:
$(文档).ready(函数(){
$('#link_other a').attr('target','u blank');
});
//不使用jquery
window.onload=函数(){
var anchors=document.getElementById('link_other').getElementsByTagName('a');
对于(var i=0;i之前在此处回答:
代码:
/* here are two different ways to do this */
//using jquery:
$(document).ready(function(){
$('#link_other a').attr('target', '_blank');
});
// not using jquery
window.onload = function(){
var anchors = document.getElementById('link_other').getElementsByTagName('a');
for (var i=0; i<anchors.length; i++){
anchors[i].setAttribute('target', '_blank');
}
}
// jquery is prettier. :-)
/*这里有两种不同的方法*/
//使用jquery:
$(文档).ready(函数(){
$('#link_other a').attr('target','u blank');
});
//不使用jquery
window.onload=函数(){
var anchors=document.getElementById('link_other').getElementsByTagName('a');
对于(var i=0;i您根本不需要JavaScript。您可以使用head
中的base
元素为锚定指定基本URL或目标
将在新窗口和/或选项卡中打开页面上的所有链接
有关基本元素的更多信息,请访问。您根本不需要JavaScript。您可以使用标题中的base
元素指定锚定的基本URL或目标
将在新窗口和/或选项卡中打开页面上的所有链接
有关基本元素的更多信息可以在上找到。切题旁,但仅仅修改标记是否更有意义?您是否试图避免搜索和替换?是的,在我的网站中有很多链接,很难在所有链接中键入它。切题旁,但仅仅修改标记是否更有意义你想避免搜索和替换吗?是的,在我的网站上有很多链接,很难在所有链接中键入。谢谢!!!成功了。因为我不能在付费的地方学习,所以什么是免费的我在学习,但它不起作用。谢谢!!!成功了。因为我不能在付费的地方学习,所以什么是免费的我在学习,但它不起作用。