使用javascript交换标题和标记
我在第三方网站上有html代码:使用javascript交换标题和标记,javascript,html,replace,greasemonkey,swap,Javascript,Html,Replace,Greasemonkey,Swap,我在第三方网站上有html代码: <div class="info_texts"> <a href="down.php?action=details&id=111" onclick="get_file(111); return false;" title="TOO LONGER TEXT, TOO LONGER TEXT, TOO LONGER TEXT, TOO LONGER TEXT, TOO LONGER TEXT, TOO LONGER TE
<div class="info_texts">
<a href="down.php?action=details&id=111"
onclick="get_file(111); return false;"
title="TOO LONGER TEXT, TOO LONGER TEXT, TOO LONGER TEXT, TOO LONGER TEXT, TOO LONGER TEXT, TOO LONGER TEXT, TOO LONGER TEXT">
<nobr>TOO LONGER TEXT, TOO LONGER TEXT, TOO...</nobr>
</a>
</div>
现在我看到截断的文本(短文本…)没有完整的文本(全文,没有…)
我想用Javascript(greasemonkey脚本)交换title=“”
在网站上有很多
,所以应该替换所有的标签
谢谢大家! 下面是一个示例代码:
// get all a tags with title inside div info_texts
var a = document.querySelectorAll('div.info_texts a[title]');
// loop through them
for (var i = 0, len = a.length; i < len; i++) {
// use one of these
// --------------------------------
// 1- replaces the entire content including <nobr>
a[i].textContent = a[i].title;
// 2- if you want to keep <nobr>
var nobr = a[i].querySelector('nobr');
if (nobr) { nobr.textContent = a[i].title; }
// 3- combination of both above methods
var nobr = a[i].querySelector('nobr');
if (nobr) { nobr.textContent = a[i].title; }
else { a[i].textContent = a[i].title; }
// 4- more error checking, in case title is blank
if (!a[i].title.trim()) { continue; }
var nobr = a[i].querySelector('nobr');
if (nobr) { nobr.textContent = a[i].title; }
else { a[i].textContent = a[i].title; }
}
//获取div info\u文本中标题为的所有a标记
var a=document.querySelectorAll('div.info_text a[title]”);
//循环通过它们
对于(变量i=0,len=a.length;i
我能用纯Javascript回答吗该站点有很多“信息文本”div,但您的代码只能读取第一个div,而不能读取所有div。@user7339814。。。哎呀,有个打字错误。。。固定的