I recently worked on a project, and many functions were related to pop-up boxes. I used to think that pop-up boxes were just that kind of thing, which was easy to implement, but recently I started to implement this function, and found that there were many problems that I had not considered.
For example, regarding some pop-up boxes for adding, deleting, and modifying, when adding some users, some information about the user, setting passwords and other information must be submitted in the pop-up box. When modifying, according to the user's name and ID number to change passwords, etc.
An example is as follows:
$(function(){
var $window = $(window),
$doc = $(document),
$body = $('body');
//关于管理员添加删除的js代码
var tabLi=$(".tabPanel").find("li");
tabLi.hover(function(){
$(this).addClass("hover").siblings().removeClass("hover");
},function(){})
/*弹出框定位*/
$(window).scroll(function() {
var pwdTips =$(".pwdTips");
var height=pwdTips.height();
var width=pwdTips.width();
var bodyHieght=$(window).height() ;
var bodyWidth=$(window).width() ;
if(!pwdTips.is(":hidden")){
pwdTips.css({
position: "fixed",
top: (bodyHieght-height)/2,
left:(bodyWidth-width)/2
});
}
});
/*弹出框定位结束*/
/*弹出框半透明背景的设置*/
var bgShadow = function(zindex) {
zindex = zindex?zindex:999;
var _bg = $('div.pwdTipsBg'),
bg_html = '
';
if(_bg.length === 0) {
_bg = $(bg_html);
}
$body.append(_bg);
_bg.css({
position : 'absolute',
top : '0px',
left : '0px',
width : $window.scrollLeft() $window.width() 'px',
height : $doc.height(),
'z-index' : zindex
});
return _bg;
};
/*弹出框半透明背景的设置*/
/*绑定事件*/
var bindClick = function(obj,handlerEvent){
obj.bind("click",function(e){
e.preventDefault();
bgShadow(1001);
var select=$(this).attr('contentid');
var onLineId=$(this).attr('id');
var pwdTips=$(select);
if(handlerEvent!=null)
{
handlerEvent($(this));
}
pwdTips.show();
pwdTips.find(".closeBtn,.diaSmtRst").click(function(){
pwdTips.hide();
var _bg = $('div.pwdTipsBg');
_bg.remove();
});
pwdTips.find('#onLineId').val(onLineId);
});
};
var show=tabLi.find("dt"),
addPanelBtn=$(".addPanelBtn"),
clickBtn=$(".clickBtn");
var setValue= function(obj){
if($(obj).is('.addPanelBtn'))
{
$('#opename').attr('value',"");
$('#pwdRest').find('#userName').show();
}
else
{
$('#pwdRest').find('#userName').hide();
$('#opename').attr('value',obj.text());
$("input.shareId").attr('value',obj.attr('id'))
}
}
$(function(){
bindClick(show,setValue);
bindClick(addPanelBtn,setValue);
bindClick(clickBtn,setValue);
});
})