当单击按钮"submit“时,我尝试在一个表单中删除3个输入元素的类,但延迟5秒之后。我知道我必须使用setTimeout函数,但是我不知道如何构建我的代码,所以它可以正常工作。
这是我写的代码(很简单)
jQuery(document).ready(function(){
jQuery(".contacts-submit").click(function() {
jQuery('#input-1').removeClass('input--filled');
jQuery('#input-2').removeClass('input--filled');
jQuery('#input-3').removeClass('input--filled');
});
});发布于 2018-08-22 14:22:00
这是如何使用setTimeout函数来实现的:
jQuery(document).ready(function(){
jQuery(".contacts-submit").click(function() {
setTimeout(function() { // This anonymous function will be called
jQuery('#input-1').removeClass('input--filled');
jQuery('#input-2').removeClass('input--filled');
jQuery('#input-3').removeClass('input--filled');
}, 5000); // After 5000ms, (5 seconds)
});
});发布于 2018-08-22 14:22:05
只需在setTimeout中包装所有所需的功能即可。也没有必要重复你自己,你可以做到这一切在一个选择器。
jQuery(document).ready(function(){
jQuery(".contacts-submit").click(function() {
setTimeout(function(){
jQuery('#input-1, #input-2, #input-3').removeClass('input--filled');
},5000);
});
});https://stackoverflow.com/questions/51968965
复制相似问题