[英]Using jQuery UI modal dialog as confirm
Is there a way i can use a jQuery UI based modal dialog for confirmation instead of the normal JS confirm()?有没有办法可以使用基于 jQuery UI 的模态对话框进行确认而不是普通的 JS 确认()? I would like to be able to do something like:
我希望能够执行以下操作:
if (jquery_ui_confirm('Are you sure?')) {
// do something
}
Thanks in advance.提前致谢。
var jqConfirm = function(msg, success) {
var dialogObj = $("<div style='display:none'>"+msg+"</div>");
$("body").append(dialogObj);
$(dialogObj).dialog({
resizable: false,
height:140,
modal: true,
buttons: {
"OK": function() {
success();
$( this ).dialog( "close" );
},
Cancel: function() {
$( this ).dialog( "close" );
}
}
});
};
Call this function using调用这个函数使用
jqConfirm("This will delete all records", function(){ /*do something here */});
yes you can.. you can provide requried html to dialog是的,你可以……你可以向对话框提供所需的 html
<script>
$(function() {
$( "#dialog-confirm" ).dialog({
resizable: false,
height:140,
modal: true,
buttons: {
"OK": function() {
$( this ).dialog( "close" );
},
Cancel: function() {
$( this ).dialog( "close" );
}
}
});
});
</script>
HTML Code HTML代码
<div id="dialog-confirm" title="Confirmation Dialog">
<p>
<span class="ui-icon ui-icon-alert"
style="float: left; margin: 0 7px 20px 0;"></span>Would you like to delete this item?
</p>
</div>
you can also use Jquery Alert plugin as well.您也可以使用 Jquery Alert 插件。 Here is a link: http://labs.abeautifulsite.net/archived/jquery-alerts/demo/
这是一个链接: http : //labs.abeautifulsite.net/archived/jquery-alerts/demo/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.