javascript timeout/sleep using setTimeout()
问题 How can I set a 2 second timeout to wait for page controls to be populated? I want to use javascript I have tried the following but to no avail: setTimeout(function(){},2000); setTimeout(2000); Anyone able to provide a pointer? 回答1: setTimeout(function(){ //put your code in here to be delayed by 2 seconds },2000); The code you want to delay needs to sit inside the setTimeout function. 回答2: Try like this $('input').click(function () { var that = $(this); setTimeout(function() { alertMsg(that);