A few days ago, when adding the modification function, I suddenly used it A prompt function, I don’t understand it a bit. After reading its origin, I decided to take notes. I feel that it will definitely be used in future development. There are some parts that I don’t quite understand, so I will slowly correct them and make corrections in the future.
JS jump used in Htm page:
$("#lyy_real").click(function(){
$.post("api/realnamechange.php",
{uname:$("#uname").val(),uid:$("#uid").val(),realname:$("#realname_lyy").val()},
Function (data) {data returns the execution of the pop -up box and refresh the current page.
popup.open(data, 'confirm', 'home.php?mod=space&uid=' $("#uid").val());
}
);
})
Common.js
var POPMENU = new Object;
var popup = {
init : function() {
var $this = this;
$('.popup').each(function(index, obj) {
since?
var pop = $(obj.attr('href'));if(pop && pop.attr('popup')) {
pop.css({'display':'none'});
$this.open(pop);
}
});
this.maskinit();
},
maskinit: function() {
var $this = this;
$('#mask').off().on('tap', function() {
$this.close();
});
},
open : function(pop, type, url) {
this.close();
this.maskinit();
if(typeof pop == 'string') {
$('#ntcmsg').remove();
if(type == 'alert') {
pop = '
} else if(type == 'confirm') {
pop = '
}
$('body').append('
');pop = $('#ntcmsg');
}
if(POPMENU[pop.attr('id')]) {
$('#' + pop.attr('id') + '_popmenu').html(pop.html()).css({'height':pop.height()+'px', 'width':pop.width()+'px'});
} else {
pop.parent().append('
');}
var popupobj = $('#' pop.attr('id') '_popmenu');
var left = (window.innerWidth - popupobj.width()) / 2;
var top = (document.documentElement.clientHeight - popupobj.height()) / 2;
popupobj.css({'display':'block','position':'fixed','left':left,'top':top,'z-index':120,'opacity':1});
$('#mask').css({'display':'block','width':'100%','height':'100%','position':'fixed','top':'0','left':'0','background':'black','opacity':'0.2','z-index':'100'});
POPMENU[pop.attr('id')] = pop;
},
close : function() {
$('#mask').css('display', 'none');
$.each(POPMENU, function(index, obj) {
$('#' index '_popmenu').css('display','none');
});
}
};
上面是popup的定义,下面是他的三种用法:
popup.open('要输出的提示信息', 'confirm', '点击确定按钮后要跳转的地址'); confirm为弹出提示框的方式,这种方式有确认和取消两种按钮,点击确定后才会跳转。
popup.open('要输出的提示信息', 'alert');alert为弹出提示框的方式,这种方式只有一个确定按钮,如果下面有跳转链接,不点击也会在默认时间内跳转页面。
popup.close();隐藏当前窗体