前言
- 最近在使用Alert提示框的時候,感覺樣式單一,很不美觀,而且自定義很是受限。爲了使提示框能夠美麗動人,SweetAlert是很不錯的選擇,它允許自定義,支持設置提示框標題、提示類型、內容展示圖片、確認取消按鈕文本、點擊後回調函數等。sweetAlert能夠自動居中,不論是電腦桌面還是移動設備,都能夠高度自定義。
- 該博客僅僅就安裝和使用做簡單記錄,至於詳細講解,sweetalert的手冊及網上資源比比皆是。可以參照以下鏈接
http://t4t5.github.io/sweetalert/
http://www.shouce.ren/post/view/id/113125
http://www.htmleaf.com/jQuery/Lightbox-Dialog/20141218888.html
安裝及使用
安裝:npm install sweetalert --save
使用:在html中加載js和css
可以使用國內免費bootcdn服務
> http://www.bootcdn.cn/sweetalert/
添加:<link href="//cdn.bootcss.com/sweetalert/1.1.3/sweetalert.css" rel="stylesheet">
<script src="//cdn.bootcss.com/sweetalert/1.1.3/sweetalert.min.js"></script>
簡單實例
swal("", "輸入的數值不合法,請輸入大於0的整數", "warning");
至此,就能獲得比BOM alert更好效果的提示框,想要更加漂亮和更多行爲的sweetalert,查看sweetalert手冊,你能獲得更多的驚喜