ash*_*n12 2 javascript sweetalert sweetalert2
如何在此JavaScript代码中显示SweetAlert?
function removeReg(del_reg) {
if (confirm("Are you sure you want to delete? \n the reg name : " + del_reg)) {
// Code goes here
}
}
Run Code Online (Sandbox Code Playgroud)
我只想在if条件下调用SweetAlert ,即在SweetAlert中,我需要显示消息"Are you sure you want to delete?".
打电话swal()与您的自定义选项的removeReg(del_reg)功能,并使用Promise由归国swal()确定什么是用户的选择:
YES,返回的value将是trueNO或按下Esc键,返回的value将是nullvar button = document.getElementById('remBtn')
function removeReg(del_reg) {
swal({
text: "Are you sure you want to delete? \n the reg name : " + del_reg,
icon: "error",
buttons: ['NO', 'YES'],
dangerMode: true
})
.then(function(value) {
console.log('returned value:', value);
});
}
button.addEventListener('click', function() {
console.log('clicked on button')
removeReg('SomeCustomRegName');
});Run Code Online (Sandbox Code Playgroud)
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<button id="remBtn">Remove Registered Name</button>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1245 次 |
| 最近记录: |