如何在此 JavaScript 代码中显示 SweetAlert?
function removeReg(del_reg) {
if (confirm("Are you sure you want to delete? \n the reg name : " + del_reg)) {
// Code goes here
}
}
我只想在中调用 SweetAlertif
条件,即在 SweetAlert 中,我需要显示消息"Are you sure you want to delete?"
.
Call swal()与您的自定义选项 https://sweetalert.js.org/guides/#using-options in the removeReg(del_reg)
功能并使用Promise https://sweetalert.js.org/guides/#using-promises由返回swal()
确定用户的选择:
- 如果用户点击了
YES
,返回的value
将true
- If the user clicked
NO
or pressed the Esc key, the returned value
will be null
var 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');
});
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<button id="remBtn">Remove Registered Name</button>
更多关于 SweetAlert 的高级示例 https://sweetalert.js.org/guides/#advanced-examples
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)