/** * */ (function($) { // 蒙板div私有属性 var div_mask = { id : '_j_div_mask_', css : { "clear" : "both", "float" : "left", "z-index" : "10000", "position" : "fixed", "top" : "0px", "left" : "0px", "cursor" : "not-allowed", 'border' : 'none' } }; // 消息框div私有属性 var div_msg_box = { id : '_j_div_msg_box_', css : { "z-index" : "10000", "position" : "fixed", 'border' : '2px solid #2484c2', 'background-color' : 'white', 'cursor' : 'default', 'border-radius' : '8px', '-moz-border-radius' : '8px', '-webkit-border-radius' : '8px' } }; // 消息框标题头div私有属性 var div_msg_box_header = { id : '_j_div_msg_box_header_', css : { 'padding' : '1px 5px', 'color' : 'white', 'background-color' : '#2484c2', 'line-height' : '26px', 'font-weight' : 'bold', 'border' : 'none' } }; // 消息框消息正文div私有属性 var div_msg_box_message = { id : '_j_div_msg_box_message_id', css : { 'overflow' : 'hidden', 'padding-left' : '10px', 'padding-top' : '10px', "border-width" : '0px' } }; // 消息框底部(操作按钮)div私有属性 var div_msg_box_bottom = { id : '_j_div_msg_box_bottom_', css : { 'text-align' : 'center', "border-width" : '0px' } }; // 消息框按钮私有属性 var div_msg_box_btn = { css : { 'cursor' : 'pointer', 'width' : '60px', 'line-height' : '24px', 'margin-top' : '5px', 'margin-right' : '10px', 'color' : '#fff', 'background' : '#1b78b4', 'display' : 'inline-block', 'font-size' : '12px' } }; /** * 创建div元素对象 * * @param {string} * id 元素id属性 * @param {string} * text 元素text属性 * @param {object} * 元素样式对象 * @return * *
* jQuery('<div id="" style='css'>text</div>')
*
*/
function creatediv(id, text, css) {
return $('
* jQuery('
* <div id="msgbox">
* <div id="header"></div>
* <div id="message"></div>
* <div id="bottom"></div>
* </div>
* ')对象
*
*/
function msgBox(title, msg, width, height) {
var bwh = browser_width_high();
// 滚动条滚动过的宽+(可视窗口宽-消息框宽)/2
var x = (bwh.b_c_w - width) / 2;
var y = (bwh.b_c_h - height) / 2;
var $box_core = creatediv(div_msg_box.id, '', div_msg_box.css).css({
'left' : x,
'top' : y,
'width' : width,
'height' : height
});
$box_core.append(msgBox_header(title));
$box_core.append(msgBox_message(msg).css({
'height' : height - 74
}));
$box_core.append(msgBox_bottom());
return $box_core;
}
/**
* 消息框按钮.生成name代码,并绑定onclick事件
*
* @param {string}
* 按钮显示名称
* @param {function}
* 按钮触发事件
* @return 返回jQuery('name')对象
*/
function msgBox_btn(name, fn) {
return $('' + name + '').css(div_msg_box_btn.css).bind("click", fn);
}
// 浏览器宽、高 ,滚动条宽、高,滚动条滚动过的高、宽
function browser_width_high() {
return {
b_c_w : document.documentElement.clientWidth,
b_c_h : document.documentElement.clientHeight,
b_s_w : document.documentElement.scrollWidth,
b_s_h : document.documentElement.scrollHeight,
b_s_t : document.documentElement.scrollTop || document.body.scrollTop,
b_s_l : document.documentElement.scrollLeft || document.body.scrollLeft
};
}
/**
* 获取遮罩层或者消息框div对象.这里使用原始方法获取指定元素id是为了方便返回。