jQuery 警报框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3241846/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery Alert Box
提问by tony noriega
Is there a good way to set an alert with jQuery?
有没有一种用 jQuery 设置警报的好方法?
i have a PDF that i need my visitors to agree to before the proceed...
我有一个 PDF,在继续之前我需要我的访问者同意...
So: User Clicks PDF link Alert Box opens: "you must agree to our statement before we give you this PDF" I Agree button (PDF download proceeds) / I Disagree Button (box closes and original page is displayed)
所以:用户点击 PDF 链接警报框打开:“在我们给你这个 PDF 之前,你必须同意我们的声明”我同意按钮(PDF 下载继续)/我不同意按钮(框关闭并显示原始页面)
Is that the best method to handle this?
这是处理这个问题的最佳方法吗?
Should i use a dialog box?
我应该使用对话框吗?
回答by data
I would suggest using a modal confirmation dialog. It also blends out the background, making the dialog more prominent.
我建议使用模态确认对话框。它还混合了背景,使对话框更加突出。
The documentation is under http://jqueryui.com/demos/dialog/#modal-confirmation
回答by conners
I have found after MUCH messing the best way is this as an easy way of emulating the javascript native alert using the dialog ui, is done as follows (which incidentally I wrote myself, because there is a high scarcity of usable stuff on this subject and lots of people whittering on about using plug ins, make a multi stage 'this' or irritating 'that' ZZZzzz...):
我发现最好的方法是这是一种使用对话框 ui 模拟 javascript 本机警报的简单方法,操作如下(顺便说一句,我自己写的,因为关于这个主题的可用东西非常稀缺,并且很多人都在谈论使用插件,制作多阶段的“这个”或刺激性的“那个”ZZZzzz...):
NB: You can't really do a equivalent of the confirm() function - without fass but you can use html rich alerts and add the events for that rich html yourself at the end of the jQueryAlery() call.
注意:您不能真正执行与 confirm() 函数相同的功能 - 没有 fass 但您可以使用 html 丰富的警报并在 jQueryAlery() 调用结束时自己添加该丰富的 html 的事件。
it works fine and includes a optional debug for 'viewing' the html or the 'url' in the case of the latter
它工作正常,并包括一个可选的调试,用于“查看”html或在后者的情况下“url”
function JQueryAlert(message,windowHeight){
/****
* equivalent to javascript 'alert'
*/
if (!windowHeight) var windowHeight = 470;
$("#msgdialog").remove();
$("body").append("<div id='msgdialog'></div>");
thatmsg = $("#msgdialog");
$("#msgdialog").dialog({
resizable: false,
draggable: false,
width: 770,
height: windowHeight,
context: thatmsg,
modal: true,
autoOpen: false,
buttons: {
"Cancel" : function (){
thatmsg.dialog("close");
}/*,
"View Source" : function (){
alert($('<div>').append($(this).clone()).html());
}*/
}
});
$("#msgdialog").html(message);
$("#msgdialog").dialog('open');
}
same as above except it goes and gets the content from a url
与上面相同,除了它从 url 获取内容
function JQueryHTML(url,windowHeight){
/****
* equivalent to javascript 'alert' but gets a url
*/
if (!windowHeight) var windowHeight = 470;
$("#dialog").remove();
$("body").append("<div id='dialog'></div>");
that = $("#dialog");
$("#dialog").dialog({
resizable: false,
draggable: false,
width: 770,
height: windowHeight,
context: that,
modal: true,
autoOpen: false,
buttons: {
"Cancel" : function (){
that.dialog("close");
}/*,
"View Source" : function (){
alert($('<div>').append($(this).clone()).html());
},
"View Url" : function (){
alert(url);
}*/
}
});
$.get(url, function(data) {
$("#dialog").html(data);
$("#dialog").dialog('open');
});
}
edit:
编辑:
I use it with the following PHP to great effect
我将它与以下 PHP 一起使用效果很好
if ($_SESSION['alert_message']){
echo "<script>\n";
echo " $(function() { \n";
echo " JQueryMessage('".str_replace("'","\'",$_SESSION['alert_message'])."'); \n";
echo " }); \n";
echo "</script>\n";
unset($_SESSION['alert_message']);
}
回答by Fury
If you want to use Jquery Alert/ Confirm/Prompt Box check out this example.
如果您想使用 Jquery 警报/确认/提示框,请查看此示例。
Or even better You should use pop-up from jquery. It looks breliant with some CSS.
甚至更好您应该使用 jquery 的弹出窗口。它看起来很漂亮,有一些 CSS。
$('#errorBtn').click(function(e) {
if (acceptCondition()=='on'){
// Prevents the default action to be triggered.
e.preventDefault();
// Triggering bPopup when click event is fired
$('#popup').bPopup({
opacity: 0.6,
zIndex: 200,
modalClose: false,
positionStyle: 'fixed'
});
You have to include jquery.bpopup-0.7.0.min.js also :)
You can reed more here at dinbror.dk
您还必须包含 jquery.bpopup-0.7.0.min.js :)
您可以在dinbror.dk 上了解更多信息