自定义消息弹出框,以便在项目中直接引用。
jquery.message.js
(function($) { /* 注册普通消息弹出框 */ var msgDiv="<div name='alertMsgDialog' title='消息' style='display:none;'>"+ "<p>"+ "<span class='ui-icon ui-icon-circle-check' style='float: left; margin: 0 7px 50px 0;'></span>"+ "<span name='message'></span>"+ "</p>"+ "</div>"; $.alertMsg=function(message){ if($("div[name=alertMsgDialog]").length==0){ $("html").append(msgDiv); } $("div[name=alertMsgDialog] span[name=message]").html(message); $("div[name=alertMsgDialog]").dialog({ modal: true, width:500, height:300, buttons: { Ok: function() { $( this ).dialog( "close" ); } } }); }; /* 注册错误消息弹出框 */ var errorMsgDiv="<div name='alertErrorMsgDialog' title='错误消息' class='ui-state-error-text' style='display:none;'>"+ "<p>"+ "<span class='ui-icon ui-icon-alert' style='float: left; margin: 0 7px 50px 0;'></span>"+ "<span name='message'></span>"+ "</p>"+ "</div>"; $.alertErrorMsg=function(message){ if($("div[name=alertErrorMsgDialog]").length==0){ $("html").append(errorMsgDiv); } $("div[name=alertErrorMsgDialog] span[name=message]").html(message); $("div[name=alertErrorMsgDialog]").dialog({ modal: true, width:500, height:300, buttons: { Ok: function() { $( this ).dialog( "close" ); } } }); }; })(jQuery);
index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script src="js/jquery.message.js"></script>
<script>
$(function(){
// 弹出普通消息
$.alertMsg("这是普通消息");
// 弹出错误消息
$.alertErrorMsg("这是错误消息");
});
</script>
</head>
<body>
</body>
</html>