---
# System prepended metadata

title: sweetalert

---

# sweetalert
head內
```
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
```
body內
```
<script>
	$(document).ready(function(){
		$('button:submit').on('click',function(e){
			e.preventDefault();
			swal({
				title:'注意',
				text:'您確定要下架嗎',
				icon:'warning',
				buttons:true,
				dangerMode:true
			}).then(function(isConfirm){
				if(isConfirm){
					setTimeout(function(){
						$('button:submit').parent().submit();
					},2000);
					
					swal('成功','您已成功下架','success');
				}else
					swal('取消','您已取消下架','error');
			});
		});
	});
</script>


```
```
$(document).ready(function(){
		$('#confirm').on('click',function(){
			swal({
				title:'注意',
				text:'請再次確認輸入的信用卡資料是否正確',
				icon:'warning',
				buttons:true,
				dangerMode:true
			}).then(function(isConfirm){
				if(isConfirm){
					//loading效果
					$('#text').show();
					$('.loader').show();
					setTimeout(function(){
						$('#text').hide();
						$('.loader').hide();
						swal('儲值成功','點數已同步更新至您的錢包','success').then(function(){
							if(isConfirm){
								window.close();	
							}
						});	
					},3500);
				} else {
					swal('取消','請重新確認信用卡資料','error');
				}
			});
		});
	});
	
```