gpt4 book ai didi

javascript - 使用 javascript 交换标题和标签

转载 作者:太空宇宙 更新时间:2023-11-04 16:12:56 25 4
gpt4 key购买 nike

我在第 3 方网站中有 html 代码:

<div class="info_texts">
<a href="down.php?action=details&amp;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>

现在我看到被 chop 的文本(短文本...),没有整个文本(全文,没有...)

我想交换title=""<nobr></nobr>使用 javacript(greasemonkey 脚本)

网站里有很多<div class="info_texts">所以应该替换所有标签。

谢谢!

最佳答案

这里是一个示例代码:

// 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; }
}

关于javascript - 使用 javascript 交换标题和标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41322089/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com