我想在关闭窗口之前向用户显示一条消息.我正在使用运行良好的SweetAlert(http://tristanedwards.me/sweetalert).
问题在于JavaScript/jQuery让我知道用户何时尝试关闭窗口/标签然后显示阻止他关闭页面的内容,除非他再次点击.
<script language="JavaScript">
window.onbeforeunload = confirmExit;
function confirmExit() {
swal("Here's a message!");
return "You have attempted to leave this page. Are you sure?";
}
</script>
Run Code Online (Sandbox Code Playgroud)
我试过这个,但它在我的SweetAlert上显示了丑陋的常见信息,任何想法?没有返回部分它无论如何关闭窗口,我试过:/
我是Javascript的新手 - 实际上是第一次编码.我正在尝试使用SweetAlert删除确认按钮.当我按下按钮时没有任何反应onclick="confirmDelete()"
.这段代码可能只是螃蟹,但这里是:
<script type="text/javascript">
function confirmDelete() {
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
)},
$.ajax({
url: "scriptDelete.php",
type: "POST",
data: {id: 5},
dataType: "html",
success: function () {
swal("Done!","It was succesfully deleted!","success");
}
});
}
</script>
<a href="#" onclick="confirmDelete()">Delete</a>
Run Code Online (Sandbox Code Playgroud)
如果删除失败,我可以添加任何警报吗?
我正在尝试使用甜蜜警报将单选按钮添加到对话框中,但我无法做到.以下是代码:
swal({
title: "<small>Please select an reason to cancel this job !</small>",
type: "warning",
text:"<input type=\"radio\" name=\"reason\" value=\"male\">Reason 1<br><input type=\"radio\" name=\"reason\" value=\"female\">Reason 2<br><input type=\"radio\" name=\"reason\" value=\"female\">Other Reason",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes",
cancelButtonText: "No",
closeOnConfirm: false,
closeOnCancel: false,
html: true
},
function(isConfirm){
if (isConfirm) {
swal("Result !","Job cancelled successfully.");
} else {
swal("Cancelled !", "Process aborted");
}
});
Run Code Online (Sandbox Code Playgroud) 我是AngularJS的新手,我正在尝试使用来自https://github.com/oitozero/ngSweetAlert的甜蜜警报插件,我已经将相应的脚本添加到我的index.html中,如下所示:
的index.html
<link rel="stylesheet" href="bower_components/sweetalert/dist/sweetalert.css">
<script src="bower_components/angular-sweetalert/SweetAlert.min.js"></script>
<script src="bower_components/sweetalert/dist/sweetalert.min.js"></script>
Run Code Online (Sandbox Code Playgroud)
正如文件所说.现在在我的ctrl.js中我有这个:
var ctrl = function ($scope, SweetAlert) {
SweetAlert.swal("Here's a message"); // this does not work
}
ctrl.$inject = ['$scope', 'oitozero.ngSweetAlert];
angular.module('myApp.missolicitudes.controllers',
[
'oitozero.ngSweetAlert'
])
.controller('MiSolicitudCtrl', ctrl);
Run Code Online (Sandbox Code Playgroud)
但是没有用,在我的浏览器上我从开发人员工具中得到了这个错误:
错误:[$ injector:unpr] http://errors.angularjs.org/1.4.3/ $ injector/unpr?p0 = oitozero.ngSweetAlertProvider%20%3C - ""itozero.ngSweetAlert%20%3C-%20MiSolicitudCtrl at错误(本机)位于http:// localhost:8081/assets/libs/angular/angular.min.js:6:416 at http:// localhost:8081/assets/libs/angular/angular.min.js:40 :375 at Object.d [as get](http:// localhost:8081/assets/libs/angular/angular.min.js:38:366)at http:// localhost:8081/assets/libs/angular/angular.min.js:40:449 at d(http:// localhost:8081/assets/libs/angular/angular.min.js:38:364)at e(http:// localhost:8081/assets/libs /angular/angular.min.js:39:124)在$ get(http:// localhost:8081/assets/libs/angular/angular)的Object.instantiate( …
您好我有一个使用sweetalert的代码
swal("Good job!", "You clicked the button!", "success")
Run Code Online (Sandbox Code Playgroud)
这段代码会弹出一条消息并且有一个按钮没关系,我喜欢做的是我想点击okay按钮后刷新页面.
我能这样做吗?
我是rails的初学者,我想在删除记录时使用Sweet Alert来替换基本的丑陋确认消息.我已经在我的宝石文件中添加了甜蜜警报宝石和甜蜜警报确认我完全按照他们在自述文件中所说的那样做了,但是它不起作用,我可以删除记录但是它立刻被删除了任何确认的消息.
的Gemfile
...
gem 'sweet-alert'
gem 'sweet-alert-confirm'
...
Run Code Online (Sandbox Code Playgroud)
Application.jssupported指令.
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require jquery.turbolinks
//= require bootstrap-sprockets
//= require sweet-alert
//= require sweet-alert-confirm
//= require_tree .
Run Code Online (Sandbox Code Playgroud)
stylesheet.css中
/*
...
*= require_self
*= require sweet-alert
*= require_tree .
*/
Run Code Online (Sandbox Code Playgroud)
index.html.erb
...
<%= link_to 'Destroy', ice_cream, method: :delete, data: { confirm: 'Are you sure?' } %>
...
Run Code Online (Sandbox Code Playgroud)
此外,还有一些我不知道是否值得一提,当我打开萤火虫时,我发现以下错误.
希望你能帮帮我,谢谢.
我想用'选择患者'更改'确定'按钮,将'取消'更改为'速度包'.我怎样才能做到这一点?
swal({
text: "Start new case by",
buttons: true,
confirmButtonText: "Select Patient?",
cancelButtonText: "Speed Case?",
});
Run Code Online (Sandbox Code Playgroud) 我喜欢javascript
确认的简单性,因此我可以这样做:
if(!confirm("are you sure?"))
return;
Run Code Online (Sandbox Code Playgroud)
在sweetalert
你有你的嵌套true
一个内码then
承诺的功能。
有没有一种方法可以像在JS确认中一样sweetalert
返回true/false
?
请帮我理解这一点。
我创建了一个 ListView,显示来自 SQL 数据库的数据。我启用了插入、编辑和删除功能,一切正常。
我想要什么?
我想用来SweetAlert
提示用户确认是/否是否要从 ListView 中删除条目。
我做了什么?
首先,我尝试使用“内置”功能,我添加OnClientClick="return confirm('are you sure')"
到<asp:Button/>
调用给定 ListView 条目的删除。那行得通!当我点击是它删除,没有它没有。除了添加上述内容之外,我无需执行任何其他操作。但这不是我想要的。我想要SweetAlert
显示鸽友,问题就在这里开始了。
其次,我认为我可以简单地创建SweetAlert
脚本并从按钮调用它的函数名称。但是,这样做时,它确实打开了,SweetAlert
但在我什至有机会单击是和否之前,它已经删除了该项目并关闭了框。
<script>
function deletealert()
{
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!",
cancelButtonText: "No, cancel plx!",
closeOnConfirm: false,
closeOnCancel: false
},
function (isConfirm) {
if …
Run Code Online (Sandbox Code Playgroud) 这是我正在处理的代码
swal({
title: "Confirm details?",
text:'<input id="datetimepicker" class="form-control" autofocus>',
type: "warning",
customClass: 'swal-custom-width',
html:true,
showCancelButton: true,
confirmButtonClass: "btn-success",
confirmButtonText: "Confirm",
cancelButtonText: "Cancel",
closeOnConfirm: false,
closeOnCancel: false,
showLoaderOnConfirm: true
},
Run Code Online (Sandbox Code Playgroud)
我想在甜蜜警报的输入中设置日期时间选择器。
$('#datetimepicker').datetimepicker({
format: 'DD/MM/YYYY hh:mm A',
defaultDate: new Date()
});
Run Code Online (Sandbox Code Playgroud)
当我单击甜蜜警报时,输入字段无法单击或对其执行任何操作。日期也没有出现。任何人都可以告诉我出了什么问题?谢谢。
单击输入选择日期时出现控制台错误
Uncaught RangeError: Maximum call stack size exceeded.
at HTMLDivElement.trigger (jquery-2.2.3.min.js:3)
at Object.trigger (jquery-2.2.3.min.js:4)
at HTMLDivElement.<anonymous> (jquery-2.2.3.min.js:4)
at Function.each (jquery-2.2.3.min.js:2)
at n.fn.init.each (jquery-2.2.3.min.js:2)
at n.fn.init.trigger (jquery-2.2.3.min.js:4)
at c.<anonymous> (bootstrap.min.js:6)
at HTMLDocument.f (jquery-2.2.3.min.js:2)
at HTMLDocument.dispatch (jquery-2.2.3.min.js:3)
at HTMLDocument.r.handle (jquery-2.2.3.min.js:3)
Run Code Online (Sandbox Code Playgroud)