这个问题在这里已经有了答案:
JQuery wait x seconds after document ready
(4 个回答)
4年前关闭。
我正在尝试自动更改输入值。这就是我所拥有的。
<input hidden="" id="inp" type="text hidden" value="YES" />
<script type="text/javascript">
function checkInputValue() {
var files = {
'YES': 'audio/timbre.mp3',
'NO': 'audio/timbre2.mp3'
};
var sound = new Audio(files[$('#inp').val()]);
sound.play();
}
checkInputValue();
</script>
HTML 中有一个隐藏的输入,默认值为“YES”。我想在 2 秒后自动将此值更改为“否”。
无论如何要这样做?
谢谢。
最佳答案
只需将其添加到代码的底部
setTimeout(function(){
document.getElementById("inp").value = "NO";
}, 2000)
setTimeout
将执行提供 function
给定时间后回调。记住时间应该以毫秒为单位2000ms == 2s
关于javascript - 自动更改输入值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47433205/