我正在尝试使用甜蜜警报作为对话框来确认删除表上的条目。每个表格行上有一列,其中有一个按钮可打开“甜蜜警报”确认对话框。
我的表的代码如下:
<tr>
<!-- Other Table Colums -->
<td>
<button userid="<?php echo $row['id']; ?>" id="<?php echo('bn_delete_' . $row['id']); ?>" class="btn btn-danger btn-xs warning-message-parameter">Delete</button>
<td>
</tr>
Run Code Online (Sandbox Code Playgroud)
我的甜蜜警报对话框的代码是:
swal({ title: "Are you sure?",
text: "You will not be able to recover this imaginary file!",
type: "warning", showCancelButton: true, confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, delete it!",
closeOnConfirm: false },
function(){
swal("Deleted!", "Your imaginary file has been deleted.", "success"); });
Run Code Online (Sandbox Code Playgroud)
当用户在对话框中单击“是”时,我想获取用户刚刚单击的按钮的 id。这样我就可以获得属性 userid 的值,然后可以使用该值从数据库中删除该条目。
我正在使用 sweetalert 来显示删除确认,并稍后在加载操作中显示时对其进行处理,虽然它不起作用,但这是代码,不起作用(它应该显示加载动画,但实际上不是这样做)有什么想法吗?
这是 JavaScript
document.querySelector('div.test').onclick = function() {
swal({
title: 'Ajax request example',
text: 'Submit to run ajax request',
type: 'info',
showCancelButton: true,
closeOnConfirm: false,
showLoaderOnConfirm: true,
}, function(){
setTimeout(function() {
swal('Ajax request finished!');
}, 2000);
});
};
Run Code Online (Sandbox Code Playgroud)
网页
<div class="test">
<button>show alert</button>
</div>
Run Code Online (Sandbox Code Playgroud)
这是小提琴
我有一个包含文本框的 sweetalert 框。sweetalert 在引导模式框中打开。在 Firefox 中,我尝试单击文本框,但它没有获得焦点。
这是我的甜蜜警报代码:
swal(
{
title: "Create New Design",
input: "text",
showCancelButton: true,
inputPlaceholder: "Title",
preConfirm: function(input)
{
// code to validate the input
}
});
Run Code Online (Sandbox Code Playgroud)
这是屏幕截图:
我是新使用 Sweet Alert,首先我将显示代码:
$('#byr').keydown(function (e){
var bayar = Number($('#byr').val());
var total = Number($('.rp-harga').text());
var kmb = $('.rp-kmb').text();
if(e.keyCode == 13)
{
if(bayar<total)
{
alert("Uang Anda Kurang");
}
else {
swal("Transaksi Berhasil", "Kembalian : Rp " + (bayar-total).toString(), "success");
}
}
});
Run Code Online (Sandbox Code Playgroud)
问题是当我用其他条件填充输入文本后按回车键时,它将显示甜蜜警报,但在我单击“确定”按钮或在出现甜蜜警报时按回车键之前,甜蜜警报将立即关闭
我尝试添加e.preventDevaults()
,并遇到这些问题:
这是一个可以解决我的问题的 JSFiddle。
有没有办法将按钮的位置或对齐方式更改为垂直而不是水平?我环顾四周,但除了更改 CSS 的提示之外,找不到任何具体内容。然而,这个选项看起来非常麻烦,并且不确定是否可行。
有人可以帮我吗?
我有模态,当我点击添加账单按钮时,它会弹出sweetalert2,下面提供的代码来自他们的文档,所以我认为代码没有问题,无论如何,我的问题是输入不能通过键入就像残疾人一样,这是materializecss方面的问题吗?
Ps我正在使用一个materializecss css框架,我还阅读了一篇文章,它在引导框架中与我有同样的问题。
https://github.com/sweetalert2/sweetalert2/issues/374
$(".btnAddBills").click(function(event) {
swal.mixin({
input: 'text',
confirmButtonText: 'Next →',
showCancelButton: true,
progressSteps: ['1', '2', '3']
}).queue([
{
title: 'Question 1',
text: 'Chaining swal2 modals is easy'
},
'Question 2',
'Question 3'
]).then((result) => {
if (result.value) {
swal({
title: 'All done!',
html:
'Your answers: <pre><code>' +
JSON.stringify(result.value) +
'</code></pre>',
confirmButtonText: 'Lovely!'
})
}
})
Run Code Online (Sandbox Code Playgroud)
});
我试图将文本放在我的 swal-box 中,但它不起作用:
CSS3:
.swal-modal {
text-align: center;
}
Run Code Online (Sandbox Code Playgroud)
JavaScript:
swal("myTitle", "some text \n some more text \n even more text);
Run Code Online (Sandbox Code Playgroud) 我不知道怎么了,我有这个JavaScript函数:
<script charset="utf-8" type="text/javascript">
$(document).ready(function(){
//initialize the javascript
App.init();
@if(Session::has('message'))
var msg = '{{ Session::get('message') }}';
console.log(msg);
swal({
title: "",
text: 'compañia',
type: "warning",
confirmButtonText: "Ok!",
closeOnConfirm: false
});
$(window).bind("load", function() {
$.gritter.add({
title: 'Atencion',
text: 'compañia',
image: '{{ asset('images/clipboard_icon.png') }}',
class_name: 'danger',
time: ''
});
return false;
});
@endif
});
</script>
Run Code Online (Sandbox Code Playgroud)
问题在于,甜蜜警报没有显示:'compañia'
它显示了,'compañia'
但是gritter消息正确显示了该单词。(见图片)
如您所见,红色的抱怨者正确地显示了该词,但甜蜜的警告却没有,
该文件是UTF-8编码的,因此元和脚本也是以防万一,在您问我为什么'compañia'
要将它放在会话中由Laravel发送并由视图以这种格式检索的较大消息的一部分时,它也是这样。
无论如何,我真正的问题是,为什么粗砂纸会显示出很好的单词,我该如何解决这个问题,使其在发出甜蜜警报时也能正常工作。
好的,首先,我是新来的.我被指示在我们的项目中使用甜蜜警报来提醒警报.我认为它会起作用,所以我在一个不同的文件上制作了一个简单的文件,并制作了类似下面的代码,但它不起作用.Sweetalert没有露面.我错过了什么?
<!DOCTYPE html>
<html>
<head>
<link href="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.css" rel="stylesheet" />
</head>
<body>
<script>
swal("Hello World");
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.js" />
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 我点击删除按钮时运行此代码:
$(document).on('click', '.remove', function (e) {
e.preventDefault();
var id = $(this).data('id');
$.ajax({
type: "POST",
url: "<?php echo Yii::$app->request->baseUrl;?>"+'/todo/deletetask',
data: {id:id},
success: function (data) {
var res = $.parseJSON(data);
if(res != false) {
swal({
title: "Are you sure!",
type: "error",
confirmButtonClass: "btn-danger",
confirmButtonText: "Yes!",
showCancelButton: true,
},
function(){
window.location.href = "<?php echo Yii::$app->request->baseUrl;?>/todo/index/";
});
}
}
});
});
Run Code Online (Sandbox Code Playgroud)
控制器动作是:
public function actionDeletetask()
{
if(Yii::$app->request->isAjax)
{
$id = $_POST['id'];
if($id)
{
Todo::find()->where(['todo_id'=>$id])->one()->delete();
}
echo json_encode(TRUE);die;
}
echo json_encode(FALSE);die;
}
Run Code Online (Sandbox Code Playgroud)
但即使我点击甜蜜警报取消按钮,任务也会被删除,这是显而易见的.但我该怎样才能阻止它呢?
我在我的应用程序中使用了几个 Node/Express 模块,只要我这样做,每个模块都可以正常工作const module = require('module');
。我不需要将这些模块的静态路径定义为app.use(express.static(path.join(__dirname, 'public')));
.
然而,对于sweetalert模块,如果我在定义layout.pug(基地哈巴狗文件)script(src="/node_modules/sweetalert/dist/sweetalert.min.js")
,我得到一个404错误(未找到),除非我在包括app.js以下静态路径:app.use("/node_modules", express.static(__dirname + "/node_modules"));
。
我的问题是:这是正常行为还是我做得不对?(我有点困惑为什么我必须为我使用的几个模块之一定义一个静态路径。
我有一个将数据插入 MySQL 的代码,该代码运行良好,我想将当前的 java 脚本警报替换为 sweetalert2。我浏览了所有论坛但找不到任何东西。谁能帮我?谢谢。
<?php
//session_start();
//include "dbcon.php";
error_reporting(0);
$conn = new PDO('mysql:host=localhost; dbname=fleet','root', 'root');
$department=$_POST['department'];
$employee=$_POST['employee'];
$approver=$_POST['approver'];
$depart_date=$_POST['depart_date'];
$return_date=$_POST['return_date'];
$depart_time=$_POST['depart_time'];
$return_time=$_POST['return_time'];
$depart_place=$_POST['depart_place'];
$arrival_place=$_POST['arrival_place'];
$reason=$_POST['reason'];
$request_timestamp=$_POST['request_timestamp'];
$approver_email = $_POST['approver_email'];
//employee_name = $_POST['employee_name'];
$employee_name = $_POST['employee_name'];
$approver_name = $_POST['approver_name'];
$employee_title = $_POST['employee_title'];
//$no_of_passengers = '';
//$name_of_passengers = '';
$no_of_passengers = $_POST['no_of_passengers'];
$name_of_passengers = $_POST['name_of_passengers'];
//$no_of_passengers2 = $_POST['no_of_passengers2'];
//$name_of_passengers2 = $_POST['name_of_passengers2'];
//$no_of_passengers2 = '';
//$name_of_passengers2 = '';
$sql2='';
//include "mail.php";
// $no_of_passengers2 = $_POST['no_of_passengers2'];
// $name_of_passengers2 = $_POST['name_of_passengers2'];
if (isset($_POST['submit'])) …
Run Code Online (Sandbox Code Playgroud) sweetalert ×12
javascript ×9
sweetalert2 ×4
jquery ×3
css ×2
php ×2
alert ×1
echo ×1
express ×1
firefox ×1
materialize ×1
node.js ×1
path ×1
utf-8 ×1