我可以延迟 jquery 的警报吗?
Can I delay an alert in jquery?
我希望在这么多秒后而不是立即出现警报,有什么方法可以在 jquery 中做到这一点?到目前为止,我已经尝试了以下方法,但我相信延迟是专门针对动画的。谢谢
alert ("Death").delay(1000);
setTimeout(function() { alert("Death"); }, 1000);
不需要 jquery 只需将其粘贴在普通的旧 setTimeout
中即可
setTimeout(function () {
alert();
}, 1000);
文档https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setTimeout
如果您使用某些框架(例如 angular),请加入绑定,它们有自己的 'variants' 来处理数据绑定等。仅供参考。
是的,通过回调:
function sample() {
alert("This is sample function");
}
$(function() {
$("#button").click(function() {
setTimeout(sample, 2000);
});
});
最简单的方法是 setTimeout
,但如果您使用的是 underscore.js,您可以这样做:-
_.delay(alert, 1000, "Death");
_.delay(function, wait, *arguments)
是的,除了设置超时。您也可以附加警报或提示
setTimeout(function() {
var addmust = prompt("Please if you dont mind may we Know who you are");
$("#addname").append(addmust);
}, 6000);
html代码
<p>Please rate us <span id="addname"></span>
我希望在这么多秒后而不是立即出现警报,有什么方法可以在 jquery 中做到这一点?到目前为止,我已经尝试了以下方法,但我相信延迟是专门针对动画的。谢谢
alert ("Death").delay(1000);
setTimeout(function() { alert("Death"); }, 1000);
不需要 jquery 只需将其粘贴在普通的旧 setTimeout
setTimeout(function () {
alert();
}, 1000);
文档https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setTimeout
如果您使用某些框架(例如 angular),请加入绑定,它们有自己的 'variants' 来处理数据绑定等。仅供参考。
是的,通过回调:
function sample() {
alert("This is sample function");
}
$(function() {
$("#button").click(function() {
setTimeout(sample, 2000);
});
});
最简单的方法是 setTimeout
,但如果您使用的是 underscore.js,您可以这样做:-
_.delay(alert, 1000, "Death");
_.delay(function, wait, *arguments)
是的,除了设置超时。您也可以附加警报或提示
setTimeout(function() {
var addmust = prompt("Please if you dont mind may we Know who you are");
$("#addname").append(addmust);
}, 6000);
html代码
<p>Please rate us <span id="addname"></span>