gpt4 book ai didi

javascript - 如何制作一个自动单击具有特定 rel 属性的 anchor 标记的按钮?

转载 作者:行者123 更新时间:2023-11-28 16:54:44 25 4
gpt4 key购买 nike

我正在尝试制作一个 float 在右上角的按钮,用于单击 rel 属性设置为“next”的 anchor 标记。该标签的代码是: <a href="website" rel="next"><span class="meta-nav screen-reader-text">Next Post</span> Next Chapter</a>

到目前为止我已经写了这个:

    var button = document.createElement("Button");
button.innerHTML = "Next";
button.style = "top:0;right:0;position:fixed;z-index: 9999"
button.onclick = function(){
var x = document.querySelector("a");
for (var i = 0; i < x.length; i++) {
if(document.x[i].rel = "next"){
window.location.href = x[i].href;
}
}
}
document.body.appendChild(button);

当我单击生成的按钮时,它不会单击 anchor 标记。有人可以帮忙吗?

最佳答案

你想要这样的东西:

var button = document.createElement("Button");
button.innerHTML = "Title";
button.style = "top:0;right:0;position:fixed;z-index: 9999"
button.onclick = function(){
var x = document.querySelector("a[rel='next']");
window.location.href = x.href;
}
document.body.appendChild(button);

查看这个jsfiddle:https://jsfiddle.net/nharding/f3m6h74r/18/

关于javascript - 如何制作一个自动单击具有特定 rel 属性的 anchor 标记的按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59432303/

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