有没有办法可以使用基于jQuery UI的模态对话框进行确认而不是普通的JS confirm()?我希望能够做到这样的事情:
if (jquery_ui_confirm('Are you sure?')) {
// do something
}
提前致谢。
答案 0 :(得分:3)
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" );
}
}
});
};
使用
调用此函数jqConfirm("This will delete all records", function(){ /*do something here */});
答案 1 :(得分:0)
是的,你可以..你可以提供所需的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代码
<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>
答案 2 :(得分:0)
您也可以使用Jquery Alert插件。这是一个链接:http://labs.abeautifulsite.net/archived/jquery-alerts/demo/