1、页面
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%><%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!doctype html>
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<title>兑换列表</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<meta name="apple-touch-fullscreen" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="static/css/reset.css" type="text/css" rel="stylesheet" />
<link href="static/css/style.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="static/js/jquery-1.8.3.min.js"></script>
<%--<script type="text/javascript" src="static/js/jquery.modal.dialog.js"></script>--%>
<script type="text/javascript" src="static/js/jquery.tips.js"></script>
<script>
//打开兑换窗口
var goodsid;
function exchange(id,exchangegift,exchangepoints){
goodsid = id;
$("#ex1").empty();
var html = "";
var openId = $("#openId").val();
var allScore = $("#allScore").val();
html += '<a href="#" rel="dialog:close"></a>'+
'<ul class="tan_s clearfix">'+
'<li class="m1"><img src="static/images/jifen-icon9.png"></li>'+
'<li class="m2"> 当前积分:<span style="font-size:1.4em;">'+allScore+'</span></br>'+
'兑换<span>'+exchangegift+'</span>将消耗您<span>'+exchangepoints+'</span>积分 </li>'+
'</ul>'+
'<ul class="tan_x">'+
'<li class="x1"><img src="static/images/jifen-icon10.jpg"></li>'+
'<li class="x2">'+
'<input type="text" id="phone" maxlength="11"/>'+
'</li>'+
'<li class="x3"><a οnclick="change()">更换号码</a></li>'+
'</ul>'+
'<div class="dh_top">'+
'<ul>'+
'<li class="dh1">'+
'<input type="checkbox" id="rule" οnclick="checkbox()"/>'+
'</li>'+
'<li class="">我已阅读并同意兑换规则</li>'+
'</ul>'+
'</div>'+
'<div class="tan_dui"><a style="background:#EEE" id="closedialog" οnclick="exchange2('+allScore+','+exchangepoints+')">立即兑换</a> </div>';
$("#ex1").append(html);
}
//验证
function check(){
if($("#rule").is(":checked")==false){
/*$("#rule").tips({
side:3,
msg:'请仔细阅读兑换规则',
bg:'#AE81FF',
time:2
});*/
$("#closedialog").attr("disabled",$("#rule").is(":checked")==false);
return false;
}
if(($("#phone").val()=="")){
$("#phone").tips({
side:3,
msg:'电话号码不能为空',
bg:'#AE81FF',
time:2
});
$("#phone").focus();
return false;
}
var phoneNumReg = /(^[0-9]{3,4}\-{0,1}[0-9]{3,8}$)|(^[0-9]{3,8}$)|(^\([0-9]{3,4}\)[0-9]{3,8}$)|(^0{0,1}13[0-9]{9}$)/;
if(!phoneNumReg.test($("#phone").val())){
$("#phone").tips({
side:3,
msg:'请填写正确的电话号码',
bg:'#AE81FF',
time:2
});
return false;
}
return true;
}
</script>
</head>
<body style="background:#fff;">
<input value="${pd.openId }" id="openId" type="hidden">
<input value="${allScore }" id="allScore" type="hidden">
<div class=" duihuan">
<div class="dh_banner"> <img src="static/images/jifen-img3.jpg"> </div>
<div class="dh_jifen"> 当前积分:
<p>${allScore }<span>积分</span></p>
</div>
<div class="dh_list">
<ul>
<c:forEach items="${varList}" var="var" varStatus="vs">
<li><a id="diag" οnclick="exchange('${var.id }','${var.exchangegift}','${var.exchangepoints}')" href="#ex1" rel="dialog:open"><img src="${var.pic}"></a>
</li>
</c:forEach>
</ul>
</div>
<div id="ex1" class="dh_top_tan" style ="display:none"></div>
</div>
</div>
<!--duihuan ed-->
</body>
</html>
2、jquery.modal.dialog.js
/*
A simple jQuery modal dialog (https://github.com/hinet/jquery.modal.dialog)
Version 0.5.6
*/
(function($) {
var current = null;
$.dialog = function(el, options) {
$.dialog.close(); // Close any open dialogs.
var remove, target;
this.$body = $('body');
this.options = $.extend({}, $.dialog.defaults, options);
this.options.doFade = !isNaN(parseInt(this.options.fadeDuration, 10));
if (el.is('a')) {
target = el.attr('href');
//Select element by id from href
if (/^#/.test(target)) {
this.$elm = $(target);
if (this.$elm.length !== 1) return null;
this.open();
//AJAX
} else {
this.$elm = $('<div>');
this.$body.append(this.$elm);
remove = function(event, dialog) { dialog.elm.remove(); };
this.showSpinner();
el.trigger($.dialog.AJAX_SEND);
$.get(target).done(function(html) {
if (!current) return;
el.trigger($.dialog.AJAX_SUCCESS);
current.$elm.empty().append(html).on($.dialog.CLOSE, remove);
current.hideSpinner();
current.open();
el.trigger($.dialog.AJAX_COMPLETE);
}).fail(function() {
el.trigger($.dialog.AJAX_FAIL);
current.hideSpinner();
el.trigger($.dialog.AJAX_COMPLETE);
});
}
} else {
this.$elm = el;
this.$body.append(this.$elm);
this.open();
}
};
$.dialog.prototype = {
constructor: $.dialog,
open: function() {
var m = this;
if(this.options.doFade) {
this.block();
setTimeout(function() {
m.show();
}, this.options.fadeDuration * this.options.fadeDelay);
} else {
this.block();
this.show();
}
if (this.options.escapeClose) {
$(document).on('keydown.dialog', function(event) {
if (event.which == 27) $.dialog.close();
});
}
if (this.options.clickClose) this.blocker.click($.dialog.close);
},
close: function() {
this.unblock();
this.hide();
$(document).off('keydown.dialog');
},
block: function() {
var initialOpacity = this.options.doFade ? 0 : this.options.opacity;
this.$elm.trigger($.dialog.BEFORE_BLOCK, [this._ctx()]);
this.blocker = $('<div class="jquery-dialog blocker"></div>').css({
top: 0, right: 0, bottom: 0, left: 0,
width: "100%", height: "100%",
position: "fixed",
zIndex: this.options.zIndex,
background: this.options.overlay,
opacity: initialOpacity
});
this.$body.append(this.blocker);
if(this.options.doFade) {
this.blocker.animate({opacity: this.options.opacity}, this.options.fadeDuration);
}
this.$elm.trigger($.dialog.BLOCK, [this._ctx()]);
},
unblock: function() {
if(this.options.doFade) {
this.blocker.fadeOut(this.options.fadeDuration, function() {
$(this).remove();
});
} else {
this.blocker.remove();
}
},
show: function() {
this.$elm.trigger($.dialog.BEFORE_OPEN, [this._ctx()]);
if (this.options.showClose) {
this.closeButton = $('<a href="#close-dialog" rel="dialog:close" class="close-dialog ' + this.options.closeClass + '">' + this.options.closeText + '</a>');
this.$elm.append(this.closeButton);
}
this.$elm.addClass(this.options.dialogClass + ' current');
this.center();
if(this.options.doFade) {
this.$elm.fadeIn(this.options.fadeDuration);
} else {
this.$elm.show();
}
this.$elm.trigger($.dialog.OPEN, [this._ctx()]);
},
hide: function() {
this.$elm.trigger($.dialog.BEFORE_CLOSE, [this._ctx()]);
if (this.closeButton) this.closeButton.remove();
this.$elm.removeClass('current');
if(this.options.doFade) {
this.$elm.fadeOut(this.options.fadeDuration);
} else {
this.$elm.hide();
}
this.$elm.trigger($.dialog.CLOSE, [this._ctx()]);
},
showSpinner: function() {
if (!this.options.showSpinner) return;
this.spinner = this.spinner || $('<div class="' + this.options.dialogClass + '-spinner"></div>')
.append(this.options.spinnerHtml);
this.$body.append(this.spinner);
this.spinner.show();
},
hideSpinner: function() {
if (this.spinner) this.spinner.remove();
},
center: function() {
this.$elm.css({
position: 'fixed',
top: "50%",
left: "50%",
marginTop: - (this.$elm.outerHeight() / 2),
marginLeft: - (this.$elm.outerWidth() / 2),
zIndex: this.options.zIndex + 1
});
},
//Return context for custom events
_ctx: function() {
return { elm: this.$elm, blocker: this.blocker, options: this.options };
}
};
//resize is alias for center for now
$.dialog.prototype.resize = $.dialog.prototype.center;
$.dialog.close = function(event) {
if (!current) return;
if (event) event.preventDefault();
current.close();
var that = current.$elm;
current = null;
return that;
};
$.dialog.resize = function() {
if (!current) return;
current.resize();
};
// Returns if there currently is an active dialog
$.dialog.isActive = function () {
return current ? true : false;
}
$.dialog.defaults = {
overlay: "#000",
opacity: 0.4,
zIndex: 1000,
escapeClose: true,
clickClose: true,
closeText: 'Close',
closeClass: '',
dialogClass: "dialog",
spinnerHtml: null,
showSpinner: true,
showClose: true,
fadeDuration: null, // Number of milliseconds the fade animation takes.
fadeDelay: 1.0 // Point during the overlay's fade-in that the dialog begins to fade in (.5 = 50%, 1.5 = 150%, etc.)
};
// Event constants
$.dialog.BEFORE_BLOCK = 'dialog:before-block';
$.dialog.BLOCK = 'dialog:block';
$.dialog.BEFORE_OPEN = 'dialog:before-open';
$.dialog.OPEN = 'dialog:open';
$.dialog.BEFORE_CLOSE = 'dialog:before-close';
$.dialog.CLOSE = 'dialog:close';
$.dialog.AJAX_SEND = 'dialog:ajax:send';
$.dialog.AJAX_SUCCESS = 'dialog:ajax:success';
$.dialog.AJAX_FAIL = 'dialog:ajax:fail';
$.dialog.AJAX_COMPLETE = 'dialog:ajax:complete';
$.fn.dialog = function(options){
if (this.length === 1) {
current = new $.dialog(this, options);
}
return this;
};
// Automatically bind links with rel="dialog:close" to, well, close the dialog.
$(document).on('click.dialog', 'a[rel="dialog:close"],button[rel="dialog:close"]', $.dialog.close);
$(document).on('click.dialog', 'a[rel="dialog:open"]', function(event) {
event.preventDefault();
$(this).dialog();
});
})(jQuery);