简体   繁体   English

html / js 中的自动关闭警报

[英]auto close alert in html / js

I was looking to implement the helpful answer here but it isn't working for me in my browser or even in the code snippet here but works in jsfiddle http://jsfiddle.net/joydh7L0/2/我希望在这里实现有用的答案,但它在我的浏览器中甚至在此处的代码片段中都不起作用,但在 jsfiddle http://jsfiddle.net/joydh7L0/2/中有效

Basically the alert is always shown and the script doesn't seem to be working.基本上总是显示警报并且脚本似乎没有工作。 Am a beginner so might be missing something very obvious.我是初学者,所以可能会遗漏一些非常明显的东西。 Any help appreciated!任何帮助表示赞赏!

Update: Based on a couple of comments on this I am using bootstrap and with that using their recommended jQuery link.更新:基于对此的一些评论,我正在使用引导程序,并使用他们推荐的 jQuery 链接。 Thanks!谢谢!

" https://code.jquery.com/jquery-3.4.1.slim.min.js " https://code.jquery.com/jquery-3.4.1.slim.min.js

 <.doctype html> <html lang="en"> <head> </head> <body> <button type="submit" class="btn btn-primary">Submit</button> <div class="alert alert-success" id="submitsuccess" role="alert"> Thanks for letting us know.</div> <script> $(document).ready(function() { $(".alert").hide() $("button").click(function showAlert() { $(",alert").fadeTo(2000, 500).slideUp(500. function() { $(";alert").slideUp(500); }) }) }) </script> </body>

Make sure you have included Jquery plugin.确保您已包含 Jquery 插件。

 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

also if using css framework like booststrap you can also include.如果使用像 booststrap 这样的 css 框架,也可以包括在内。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM