下面是封装的代码:
- function alert(message){
- if ($("#dialogalert").length == 0) {
- $("body").append('<div id="dialogalert"></div>');
- $("#dialogalert").dialog({
- autoOpen: false,
- title: '消息框',
- modal: true,
- resizable:false,
- overlay: {
- opacity: 0.5,
- background: "black"
- },
- buttons: {
- "确定": function(){
- $(this).dialog("close");
- }
- }
- });
- }
- $("#dialogalert").html(message);
- $("#dialogalert").dialog("open");
- }
- function confirm(message, callback){
- if ($("#dialogconfirm").length == 0) {
- $("body").append('<div id="dialogconfirm"></div>');
- $("#dialogconfirm").dialog({
- autoOpen: false,
- title: '消息框',
- modal: true,
- resizable:false,
- overlay: {
- opacity: 0.5,
- background: "black"
- },
- buttons: {
- "确定": function(){
- callback();
- $(this).dialog("close");
- },
- "取消": function(){
- $(this).dialog("close");
- }
- }
- });
- }
- $("#dialogconfirm").html(message);
- $("#dialogconfirm").dialog("open");
- }
使用方法
先导入css和javascript库(根据自己实际情况)
<link rel="stylesheet" type="text/css" href="js/themes/default/ui.all.css"/>
<script type="text/javascript" src="js/jquery-1.2.6.js"></script>
<script type="text/javascript" src="js/ui/ui.core.js"></script>
<script type="text/javascript" src="js/ui/ui.dialog.js"></script>
<script type="text/javascript" src="js/util.js"></script>
需要拖拽移动等功能,请添加相应的库
在你需要弹出消息对话框或者选择对话框时使用下面方法:
- alert("发表成功!");
- confirm("确认要删除所选?此操作不可恢复!", function(){
- $.ajax({
- url: actionurl,
- data: {
- date: new Date().getTime(),
- action: "delete",
- ids: getSelectIDs()
- },
- success: function(data){
- if (data == "1") {
- alert("删除成功!");
- getAll();
- $("#selectalllabel").html("全部选择");
- $("#selectall").removeAttr("checked");
- }
- else {
- alert("删除失败!");
- }
- idstr = "";
- }
- });
- });
学了一段时间jquery,这是我第一个原创文章,欢迎大家指教
有什么问题,大家一顶告诉我 qq:281924282 msn:java_lover@live.cn