如何使JavaScript脚本在页面中运行不止一次

发布于 2025-02-13 05:54:00 字数 312 浏览 0 评论 0原文

我的网站有按钮A。当我单击它时,出现一个弹出式div,是否选项。我必须单击是。因此,我写了一个脚本,以便当我单击按钮A时,是自动单击的“是”选项。就像这样,

buttonA.onclick = function(){
document.getElementById('buttonYes').click()
};

我将其加载到Tampermonkey中。当页面加载时,代码首次工作。之后,按钮回到了他们的原始行为。 JavaScript某人仅在新加载页面时仅能工作一次。有人可以提出一种使代码一直在页面中工作的方法,我不需要重新加载页面才能工作。

My website has button A. When I click it a pop up div appears with yes no option. I must click yes. So I write a script so that when I click button A, the yes option is automatically clicked. It goes like this

buttonA.onclick = function(){
document.getElementById('buttonYes').click()
};

I load this into Tampermonkey. When the page loads, the code work for the first time. After that the button goes back to their original behavior. The Javascript somehome only works once when the page is newly loaded. Can someone suggest a way to make the code works all the time in the page and I don't need to reload the page for it to work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文