2015-10-07 60 views
0

我没有得到甜蜜的警报,我认为它与语法有关。有人可以告诉我我应该怎么做甜蜜的警报语法

<!DOCTYPE html> 
<html> 
<head> 
    <title>Testing</title> 
    <script src="dist/sweetalert.min.js"></script> 
    <link rel="stylesheet" type="text/css" href="dist/sweetalert.css"> 
</head> 
<body> 
<script> 
    swal({ 
    title: 'Confirm', 
    text: 'Are you sure to delete this message?', 
    type: 'warning', 
    showCancelButton: true, 
    confirmButtonText: 'Yes, sir', 
    cancelButtonText: 'Not at all' 
}); 
</script> 
</body> 
</html> 
+0

您可以检查任何错误的开发者控制台? –

+0

也在控制台中是swal可用作为全局? – markyph

+0

我复制并粘贴,所以我怀疑是有错误 – 987654321

回答

3

向html添加按钮并触发onclick事件。

例如使用标准queryselectors

document.querySelector('button#test-1').onclick = function(){ 
 
    swal({ 
 
    title: 'Confirm', 
 
    text: 'Are you sure to delete this message?', 
 
    type: 'warning', 
 
    showCancelButton: true, 
 
    confirmButtonText: 'Yes, sir', 
 
    cancelButtonText: 'Not at all' 
 
    }); 
 
};
<link href="http://t4t5.github.io/sweetalert/dist/sweetalert.css" rel="stylesheet"/> 
 
<script src="http://t4t5.github.io/sweetalert/dist/sweetalert.min.js"></script> 
 
<button id="test-1">Show alert</button>

+0

我在你的答案中添加了一个片段,以便更好地使用。 – Dwza

+0

谢谢@Dwza - 将来会记得这么做 - 现在伟大的SO允许这样做。 – markyph

相关问题