jQuery:执行一个函数AFTER toggleClass被执行
16lz
2021-01-22
I have
我有
<script>
function myfunc(){
alert("show this alert in 5000ms after toggleClass executed")
//some code goes here
}
$(document).ready(function(){
$('.mybtn').on('click',function(){
$('#mydiv').toggleClass('newclass');
});
});
</script>
How to execute myfunc()
in 5000ms after toggleClass was executed? Tried several ways but with no luck.
如何在执行toggleClass后的5000ms内执行myfunc()?试过几种但没有运气的方法。
Thank you.
谢谢。
5 个解决方案
#1
7
use setTimeout()
使用setTimeout()
function myfunc() {
alert("show this alert in 5000ms after toggleClass executed")
//some code goes here
}
$(document).ready(function () {
$('.mybtn').on('click', function () {
$('#mydiv').toggleClass('newclass');
setTimeout(myfunc, 5000)
});
});
更多相关文章
- 【问题解决方案】ImportError: No module named 'pygal'
- Python 黏包及黏包解决方案
- 无法安装ndg-httpsclient或者我的解决方案错误
- Linux无法连接网络解决方案
- Media-S 简介(一个开源的DRM解决方案)
- AppScan安全问题解决方案
- PLSQL乱码解决方案
- 数据库不支持中文解决方案(mysql)
- Mysql替代解决方案Cassandra