用法:
<script type="text/javascript" src="jBox/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="jBox/jquery.jBox-2.3.min.js"></script>
<script type="text/javascript" src="jBox/i18n/jquery.jBox-zh-CN.js"></script>
<link type="text/css" rel="stylesheet" href="jBox/Skins/皮肤文件夹/jbox.css"/>
// 或
<link type="text/css" rel="stylesheet" href="jBox/Skins2/皮肤文件夹/jbox.css"/>
函数原型:
└ 或者 jBox(content, options);
参数说明:
- content (string,json)
└ 可以是string或json。当是string时,需要加上前缀标识(html:、id:、get:、post:、iframe:),如果没有加标识,系统会自动加上html:,具体请看应用例子。当是json时,表示一个或多个状态,每个状态的默认值为 $.jBox.stateDefaults。
- options [可选] (json)
└ 其它参数选项,默认值为 $.jBox.defaults。
$.jBox.defaults = {
id: null, /* 在页面中的唯一id,如果为null则自动生成随机id,一个id只会显示一个jBox */
top: '15%', /* 窗口离顶部的距离,可以是百分比或像素(如 '100px') */
border: 5, /* 窗口的外边框像素大小,必须是0以上的整数 */
opacity: 0.1, /* 窗口隔离层的透明度,如果设置为0,则不显示隔离层 */
timeout: 0, /* 窗口显示多少毫秒后自动关闭,如果设置为0,则不自动关闭 */
showType: 'fade', /* 窗口显示的类型,可选值有:show、fade、slide */
showSpeed: 'fast', /* 窗口显示的速度,可选值有:'slow'、'fast'、表示毫秒的整数 */
showIcon: true, /* 是否显示窗口标题的图标,true显示,false不显示,或自定义的CSS样式类名(以为图标为背景) */
showClose: true, /* 是否显示窗口右上角的关闭按钮 */
draggable: true, /* 是否可以拖动窗口 */
dragLimit: true, /* 在可以拖动窗口的情况下,是否限制在可视范围 */
dragClone: false, /* 在可以拖动窗口的情况下,鼠标按下时窗口是否克隆窗口 */
persistent: true, /* 在显示隔离层的情况下,点击隔离层时,是否坚持窗口不关闭 */
showScrolling: true, /* 是否显示浏览的滚动条 */
ajaxData: {}, /* 在窗口内容使用get:或post:前缀标识的情况下,ajax post的数据,例如:{ id: 1 } 或 "id=1" */
iframeScrolling: 'auto', /* 在窗口内容使用iframe:前缀标识的情况下,iframe的scrolling属性值,可选值有:'auto'、'yes'、'no' */
title: 'jBox', /* 窗口的标题 */
width: 350, /* 窗口的宽度,值为'auto'或表示像素的整数 */
height: 'auto', /* 窗口的高度,值为'auto'或表示像素的整数 */
bottomText: '', /* 窗口的按钮左边的内容,当没有按钮时此设置无效 */
buttons: { '确定': 'ok' }, /* 窗口的按钮 */
buttonsFocus: 0, /* 表示第几个按钮为默认按钮,索引从0开始 */
loaded: function (h) { }, /* 窗口加载完成后执行的函数,需要注意的是,如果是ajax或iframe也是要等加载完http请求才算窗口加载完成,
参数h表示窗口内容的jQuery对象 */
submit: function (v, h, f) { return true; },
/* 点击窗口按钮后的回调函数,返回true时表示关闭窗口,
参数有三个,v表示所点的按钮的返回值,h表示窗口内容的jQuery对象,f表示窗口内容里的form表单键值 */
closed: function () { } /* 窗口关闭后执行的函数 */
};
示例(一):
$.jBox.open("iframe:http://www.baidu.com", "百度一下", 800, 350, { buttons: { '关闭': true} });
示例(二): (content为Json对象,比较复杂一点的例子)
var html1 = '<div class="msg-div">' +
'<p>购买数量:</p><div class="field"><input type="text" id="amount" name="amount" value="1" /></div>' +
'<p>收货地址:</p><div class="field"><textarea id="address" name="address"></textarea></div>' +
'<div class="errorBlock" style="display: none;"></div>' +
'</div>';
var html2 = '<div class="msg-div">' +
'<p>给卖家留言:</p><div class="field"><textarea id="message" name="message"></textarea></div>' +
'</div>';
var data = {};
var states = {};
states.state1 = {
content: html1,
buttons: { '下一步': 1, '取消': 0 },
submit: function (v, h, f) {
if (v == 0) {
return true; // close the window
}
else {
h.find('.errorBlock').hide('fast', function () { $(this).remove(); });
data.amount = f.amount; //或 h.find('#amount').val();
if (data.amount == '' || parseInt(data.amount) < 1) {
$('<div class="errorBlock" style="display: none;">请输入购买数量!</div>').prependTo(h).show('fast');
return false;
}
data.address = f.address;
if (data.address == '') {
$('<div class="errorBlock" style="display: none;">请输入收货地址!</div>').prependTo(h).show('fast');
return false;
}
$.jBox.nextState(); //go forward
// 或 $.jBox.goToState('state2')
}
return false;
}
};
states.state2 = {
content: html2,
buttons: { '上一步': -1, '提交': 1, '取消': 0 },
buttonsFocus: 1, // focus on the second button
submit: function (v, o, f) {
if (v == 0) {
return true; // close the window
} else if (v == -1) {
$.jBox.prevState() //go back
// 或 $.jBox.goToState('state1');
}
else {
data.message = f.message;
// do ajax request here
$.jBox.nextState('<div class="msg-div">正在提交...</div>');
// 或 $.jBox.goToState('state3', '<div class="msg-div">正在提交...</div>')
// asume that the ajax is done, than show the result
var msg = [];
msg.push('<div class="msg-div">');
msg.push('<p>下面是提交的数据</p>');
for (var p in data) {
msg.push('<p>' + p + ':' + data[p] + '</p>');
}
msg.push('</div>');
window.setTimeout(function () { $.jBox.nextState(msg.join('')); }, 2000);
}
return false;
}
};
states.state3 = {
content: '',
buttons: {} // no buttons
};
states.state4 = {
content: '',
buttons: { '确定': 0 }
};
$.jBox.open(states, '提交订单', 450, 'auto');
$.jBox.prompt()
函数原型:
$.jBox.prompt(content, title, icon, options);
└ 或者 jBox.prompt(content, title, icon, options);
参数说明:
- content (string)
└ 只能是string,不支持前缀标识,默认值为''。
- title [可选] (string)
└ 窗口标题,值为null时为不显示标题,默认值为 $.jBox.defaults.title。
- icon [可选] (string)
└ 内容图标,值为'none'时为不显示图标,可选值有'none'、'info'、'question'、'success'、'warning'、'error',默认值为'none'。
- options [可选] (json)
└ 其它参数选项,默认值为 $.jBox.defaults。
备注:以下几个方法由 $.jBox.prompt() 扩展而来,参数类似,请看下面的例子。
$.jBox.alert(content, title, options);
└ 或者 jBox.alert(content, title, options);
$.jBox.info(content, title, options);
└ 或者 jBox.info(content, title, options);
$.jBox.success(content, title, options);
└ 或者 jBox.success(content, title, options);
$.jBox.error(content, title, options);
└ 或者 jBox.error(content, title, options);
$.jBox.confirm(content, title, submit, options);
└ 或者 jBox.confirm(content, title, submit, options);
$.jBox.warning(content, title, submit, options);
└ 或者 jBox.warning(content, title, submit, options);
└ 上面方法中默认按钮的文字设置在 $.jBox.languageDefaults
实例
var submit = function (v, h, f) {
if (v == 'yes') {
$.jBox.tip('已保存。', 'success');
}
if (v == 'no') {
$.jBox.tip('没保存。');
}
if (v == 'cancel') {
$.jBox.tip('已取消。');
}
return true;
};
// 可根据需求仿上例子定义按钮
$.jBox.warning("内容已修改,是否保存?", "提示", submit);
$.jBox.tip()
函数原型:
$.jBox.tip(content, icon, options);
└ 或者 jBox.tip(content, icon, options);
参数说明:
- content (string)
└ 只能是string,不支持前缀标识,默认值为''。
- icon [可选] (string)
└ 内容图标,可选值有'info'、'success'、'warning'、'error'、'loading',默认值为'info',当为'loading'时,timeout值会被设置为0,表示不会自动关闭。
- options [可选] (json)
└ 其它参数选项,默认值为 $.jBox.tipDefaults。
备注:如果想手动关闭tip,请调用 $.jBox.closeTip() 方法。
示例(一):
//加了个其它参数focusId
$.jBox.tip('关闭后设置输入框为焦点', 'info', { focusId: 'tip-input' });
$.jBox.messager()
函数原型:
$.jBox.messager(content, title, timeout, options);
└ 或者 jBox.messager(content, title, timeout, options);
参数说明:
- content (string)
└ 只能是string,不支持前缀标识,默认值为''。
- title [可选] (string)
└ 窗口标题,值为null时为不显示标题,默认值为 $.jBox.messagerDefaults.title。
- timeout [可选] (number)
└ 显示多少毫秒后自动关闭,如果为0则不自动关闭,默认值为 $.jBox.messagerDefaults.timeout。
- options [可选] (json)
└ 其它参数选项,默认值为 $.jBox.messagerDefaults。
备注:如果想手动关闭messager,请调用 $.jBox.closeMessager() 方法。
示例(一):
$.jBox.messager(‘Hello jBox’, ‘jBox’);
示例(二):
$.jBox.messager("Hello jBox 2", "my title", null, { width: 350, showType: 'fade' });
示例(三):
$.jBox.messager("Hello jBox 3", "my title", 3000, {
width: 350,
icon: 'info',
showType: 'show',
buttons: { '去看看': true },
submit: function (v, h, f) {
$.jBox.info('看个蛋蛋?');
return true;
}
});
我的实例
$("a[href=#infoModal3]").click(function(){
$.jBox("iframe:${ctx}/client/proClient/clientType", {
title: "",
top:'10px',
width: 630,
height: 500,
buttons: { '保存':"save",'取消': true } ,
persistent: true,
submit:function(v, h, f){//点击保存的时候执行此事件
if (v=="save"){//
var cname = h.find("iframe").contents()[0].inputForm[1].value;//校验客户是否填写
var subForm = h.find("iframe").contents()[0].inputForm;
if(cname==undefined||cname==''){
alertx("请填写客户名称");
return false;
}
subForm.action="${ctx}/client/proClient/saveClinet";
subForm.submit();
return false;
}
},
loaded: function (h) { //点击添加执行此事件
var clientId=h.find("iframe").contents()[0].inputForm[0].value;//获取form的第一个input
var clientName=h.find("iframe").contents()[0].inputForm[1].value;//获取form的第二个input
if(clientId!=null&&clientId!="undefined"&&clientId!=""){
$("#clienthiden").val(clientId);
$("#clientselect").val(clientName);
$.jBox.close(true); //关闭
$("#errorinfo").hide();
}
}
});
});
经过后台跳转一个jsp页面
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<link href="${ctxStatic}/jquery-jbox/2.3/Skins/Bootstrap/jbox.min.css" rel="stylesheet" />
<script src="http://code.jquery.com/jquery-migrate-1.1.1.js"></script>
<script src="${ctxStatic}/jquery-jbox/2.3/jquery.jBox-2.3.min.js" type="text/javascript"></script>
<link href="${ctxStatic}/bootstrap/2.3.2/css/bootstrap.min.css" rel="stylesheet">
<link href="${ctxStatic}/bootstrap/2.3.2/css/bootstrap.css" rel="stylesheet">
<style>
</style>
<script type="text/javascript">
</script>
</head>
<body>
<div class="panel-body">
<form:form id="inputForm" name="inputForm" modelAttribute="client" action="${ctx}/client/proClient/savesaveClinet" method="post" class="form-horizontal">
<div class="form-group">
<label class="col-sm-2 control-label">客户经理:</label>
<div class="col-sm-3">
<sys:treeselect id="saleUserId" name="saleUser.id" value="${client.saleUser.id}" labelName="saleUser.name" labelValue="${client.saleUser.name}"
title="用户" url="/sys/office/treeData?type=3&isAll=true" cssClass="form-control" allowClear="true" notAllowSelectParent="true" cssStyleBtn="float:right;margin-top:-35px;margin-right:15px"/>
</div>
</div>
<form:input type="hidden" path="id" />
<div class="form-group" >
<label class="col-sm-2 control-label" >客户名称:</label>
<div class="col-sm-10" style='width: 300px'>
<div style="float: left ;width:230px" ><form:input path="name" htmlEscape="false" maxlength="512" class="form-control required"/></div>
<div style="float: left; margin-top: 9px;margin-left: 5px"><span class="help-inline"><font color="red">*</font> </span></div>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">行业类别:</label>
<div class="col-sm-10">
<form:select path="category" class="chosen-select" >
<form:option value="" label="请选择"/>
<c:forEach items="${industryList}" var="category" varStatus="st">
<option value ="${category.id}">${category.name}</option>
</c:forEach>
</form:select>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">单位地址:</label>
<div class="col-sm-10">
<form:input path="address" htmlEscape="false" maxlength="256" class="form-control "/>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">学校网址:</label>
<div class="col-sm-10">
<form:input path="url" htmlEscape="false" maxlength="512" class="form-control url"/>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">区域:</label>
<div class="col-sm-10">
<sys:treeselect id="area" name="area.id" value="${proClient.area.id}" labelName="area.name" labelValue="${client.area.name}"
title="区域" url="/sys/area/treeData" allowClear="true" notAllowSelectParent="true" cssClass="form-control" cssStyleBtn="float:right;margin-top:-35px;margin-right:-25px"/>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">单位简介:</label>
<div class="col-sm-10">
<form:textarea path="profile" htmlEscape="false" rows="4" maxlength="255" class="input-xxlarge" style="width:440px;"/>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">备注信息:</label>
<div class="col-sm-10">
<form:textarea path="remarks" htmlEscape="false" rows="4" maxlength="255" class="input-xxlarge " style="width:440px;"/>
</div>
</div>
</form:form>
</div>
</body>
</html>