简体   繁体   English

如何在按钮上使用甜蜜警报

[英]How to use sweet alert on button

message like that像这样的消息

Swal.fire(

  'Good job!',

  'You clicked the button!',

  'success'

)

When I click my button then I want to show that message当我单击按钮时,我想显示该消息

 function alertMsg(){ Swal.fire( 'Good job,', 'You clicked the button!', 'success' ) }
 <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11.3.3/dist/sweetalert2.all.min.js"></script> <button onClick="alertMsg()">Button</button>

There are different ways to achieve this, I don't know if your button has an id or class you can attach an event for that, you should use the on click event.有不同的方法可以实现这一点,我不知道您的按钮是否有 id 或 class 您可以为此附加一个事件,您应该使用 on click 事件。 Learn more about events here.在此处了解有关活动的更多信息。

This is a simple example:这是一个简单的例子:

<button onclick="showSwalAlert()">My Button</button>
<script>
 function showSwalAlert(){
    Swal.fire(
    'Good job!',
    'You clicked the button!',
    'success'
   )
  }
</script>

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

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