使用Javascript更改按钮值/显示文本



我正在使用一个插件(所以我没有访问编辑HTML)在我的网站上的年龄验证弹出。我想更改显示在这两个按钮上的文本,这些文本当前是从HTML value属性中提取的。

输入图片描述

这是每个按钮的HTML:

<input type="button" name="confirm_age" id="confirm_age" value="I am 18 or older [Enter Site]" style="background-color:#2dc937; width:300px;" tabindex="1">

<input type="button" name="not_confirm_age" id="not_confirm_age" value="I am under 18" style="background-color:#cc3232; width:300px;" tabindex="1">

正如@vanblart所说,你可以使用:

document.querySelector("#confirm_age").value = "New Value"

如果插件需要时间来渲染按钮,你可以用setTimeout()将上面的代码包装在计时器中:

setTimeout(function() {
document.querySelector("#confirm_age").value = "New Value"
}, 2000);

最新更新