Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/457.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何更改不包含';我没有使用JavaScript的id或类_Javascript_Html - Fatal编程技术网

如何更改不包含';我没有使用JavaScript的id或类

如何更改不包含';我没有使用JavaScript的id或类,javascript,html,Javascript,Html,我无法访问承载代码片段的html文档。锚链接不正确,用户无法访问信息和工具。锚定链接位于标记的内部,该标记位于表的内部,该表位于div的内部。现在div是唯一有ID的东西,我不能将jQuery添加到这个页面包装器中,因为它已经应用于1000多个页面,所以我不想破坏任何东西 HTML: 但我不知道如何使用JavaScript实现这一点 我在想,如果有办法向锚定链接添加类或id,我可以这样做 var pcfaq = document.getElementById('wrongLinkOne'); p

我无法访问承载代码片段的html文档。锚链接不正确,用户无法访问信息和工具。锚定链接位于
标记的内部,该标记位于
表的内部,该表位于
div的内部。现在div是唯一有ID的东西,我不能将jQuery添加到这个页面包装器中,因为它已经应用于1000多个页面,所以我不想破坏任何东西

HTML:

但我不知道如何使用JavaScript实现这一点

我在想,如果有办法向锚定链接添加类或id,我可以这样做

var pcfaq = document.getElementById('wrongLinkOne');
pcfaq.href= "[[S8:PC_FAQ_updated.html]]"
(S8呈现html链接)


谢谢你的帮助

使用
document.queryselectoral()
查找
td
中的所有
a
标记。在它们上面循环,检查文本是否包含所需内容,并更改
href

document.querySelectorAll("td a").forEach(el => {
    if (a.textContent.includes("As part of your registration you will receive update emails and support from this program.")) {
        a.href = "[[S8:PC_FAQ_updated.html]]";
    }
});

使用
document.querySelectorAll()
查找
td
中的所有
a
标记。在它们上面循环,检查文本是否包含所需内容,并更改
href

document.querySelectorAll("td a").forEach(el => {
    if (a.textContent.includes("As part of your registration you will receive update emails and support from this program.")) {
        a.href = "[[S8:PC_FAQ_updated.html]]";
    }
});

对不起,
ErrorLinkOne
id在哪里?只需使用
document.querySelector
,使用合适的选择器并修改元素。@FrancoScarpa抱歉,错误链接只是我编造的一个例子,如果我能弄明白的话,我会做什么。抱歉,但是
错误链接id在哪里?只需使用
文档.querySelector
,使用适当的选择器,并根据您的需要修改元素。@FrancoScarpa抱歉,错误的LinkOne只是我编造的一个例子,如果我能弄明白的话,我会做的。太棒了!非常感谢你。我在谷歌上搜索了“如何使用javascript更改锚链接”和“使用javascript查找包含文本的元素”,但我找不到任何对我有意义的东西,哈哈。这是完美的Barmar谢谢你真棒!非常感谢你。我在谷歌上搜索了“如何使用javascript更改锚链接”和“使用javascript查找包含文本的元素”,但我找不到任何对我有意义的东西,哈哈。这是完美的Barmar谢谢
document.querySelectorAll("td a").forEach(el => {
    if (a.textContent.includes("As part of your registration you will receive update emails and support from this program.")) {
        a.href = "[[S8:PC_FAQ_updated.html]]";
    }
});