书签 分享 收藏 举报 版权申诉 / 19

类型前端弹出对话框js实现ajax交互剖析.docx

  • 文档编号:8610837
  • 上传时间:2023-02-01
  • 格式:DOCX
  • 页数:19
  • 大小:21.57KB

复制代码

接着给出选择器部分代码,也就是outil.js的代码,当然之前的jquery以及jqueryui就不说了。

其核心是绑定click事件。

复制代码

jQuery.extend({

getCookie:

function(sName){

varaCookie=document.cookie.split(";");

for(vari=0;i

varaCrumb=aCookie[i].split("=");

if(sName==aCrumb[0])returndecodeURIComponent(aCrumb[1]);

}

return'';

},

setCookie:

function(sName,sValue,sExpires){

varsCookie=sName+"="+encodeURIComponent(sValue);

if(sExpires!

=null)sCookie+=";expires="+sExpires;document.cookie=sCookie;

},

removeCookie:

function(sName){

document.cookie=sName+"=;expires=Fri,31Dec199923:

59:

59GMT;";}

});

$(function(){

/*dialog选择并绑定一个新的click事件*/

$('*[ectype="dialog"]').click(function(){

varid=$(this).attr('dialog_id');

vartitle=$(this).attr('dialog_title')?

$(this).attr('dialog_title'):

'';varurl=$(this).attr('uri');

varwidth=$(this).attr('dialog_width');ajax_form(id,title,url,width);returnfalse;

});

});

functiondrop_confirm(msg,url){

if(confirm(msg)){

window.location=url;

}

}

/*显示Ajax表单*/

functionajax_form(id,title,url,width)

{

if(!

width)

{

width=400;

}

vard=DialogManager.create(id);

d.setTitle(title);

d.setContents('ajax',url);d.setWidth(width);d.show('center');

returnd;

}

functiongo(url){

window.location=url;

}

functionset_zindex(parents,index){

$.each(parents,function(i,n){

if($(n).css('position')=='relative'){//alert('relative');

//alert($(n).css('z-index'));

$(n).css('z-index',index);

}

});

}

functionjs_success(dialog_id)

{

DialogManager.close(dialog_id);

varurl=window.location.href;

url=url.indexOf('#')>0?

url.replace(/#/g,''):

url;window.location.replace(url);

}

functionjs_fail(str)

{

$('#warning').html(''+str+'');$('#warning').show();

}

functioncheck_pint(v)

{

varregu=/人[0-9]{1,}$/;

if(!

regu.test(v))

{

alert(lang.only_int);

returnfalse;

}

returntrue;

}

/*转化JS跳转中的&*/

functiontransform_char(str)

{

if(str.indexOf('&'))

{

str=str.replace(/&/g,"%26");

}

returnstr;

}

//复制到剪贴板

functioncopyToClipboard(txt){

if(window.clipboardData){window.clipboardData.clearData();window.clipboardData.setData("Text",txt);

}elseif(navigator.userAgent.indexOf("Opera")!

=-1){window.location=txt;

}elseif(scape){

try{netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");

}catch(e){

returnfalse;

}

varclip

Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);

if(!

clip)

returnfalse;

vartrans

Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);

if(!

trans)

returnfalse;

trans.addDataFlavor('text/unicode');

varstr=newObject();

varlen=newObject();

varstr

Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);

varcopytext=txt;

str.data=copytext;

trans.setTransferData("text/unicode",str,copytext.length*2);

varclipid=Components.interfaces.nsIClipboard;

if(!

clip)

returnfalse;

clip.setData(trans,null,clipid.kGlobalClipboard);

}

}

复制代码

帮定事件的相关代码就是dialog的核心代码(dialog.js)了,这个是在网上找到的,在此感谢,代码如下所示:

复制代码

__DIALOG_WRAPPER__={};

/*IE6有个Bug,如果不给定对话框的宽度的话,在IE6下,对话框将以100%宽度显示*/

DialogManager={

'create':

function(id){

vard={};

if(!

__DIALOG_WRAPPER__[id])

{

d=newDialog(id);

__DIALOG_WRAPPER__[id]=d;

}

else

{

d=DialogManager.get(id);

}

returnd;

},

'get':

function(id){

return__DIALOG_WRAPPER__[id];

},

'close':

function(id){

if(__DIALOG_WRAPPER__[id].close())

{

__DIALOG_WRAPPER__[id]=null;

},

'onClose':

function(){

returntrue;

},

/*加载对话框样式*/

'loadStyle':

function(){

var_dialog_js_path=$('#dialog_js').attr('src');

var_path=_dialog_js_path.split('/');

var_dialog_css=_path.slice(0,_path.length-1).join('/')+'/dialog.css';

$('#dialog_js').after('');

}

};ScreenLocker={

'style':

{

'position'

:

'absolu

'top'

:

'0px',

'left'

:

'0px',

'backgroundColor'

:

'#000',

'opacity'

:

0.5,

'zIndex'

:

999

},

'masker':

null,

'lock':

function(zIndex){

if(this.masker!

==null)

{this.masker.width($(document).width()).height($(document).height());

returntrue;

}

this.masker=$('

');

/*IE6Hack*/

if($.browser.msie)

{

$('select').css('visibility','hidden');

}

//var_iframe=$('').css({'opacity':

0,'width':

'100%','height':

'100%'});//this.masker.append(_iframe);

/*样式*/

this.masker.css(this.style);

if(zIndex)

{this.masker.css('zIndex',zIndex);

}

/*整个文档的宽高*/

this.masker.width($(document).width()).height($(document).height());

$(document.body).append(this.masker);

},

'unlock':

function(){

if(this.masker===null)

{

returntrue;

}this.masker.remove();this.masker=null;

/*IE6Hack*/

if($.browser.msie)

{

$('select').css('visibility','visible');

}

}

};

Dialog=function(id){

/*构造函数生成对话框代码,并加入到文档中*/this.id=id;

this.init();

};

Dialog.prototype={

/*唯一标识*/

'id':

null,

/*文档对象*/

'dom':

null,

'lastPos':

null,

'status':

'complete',

'onClose':

function(){

returntrue;

},

'tmp':

{},

/*初始化*/

'init':

function(){

this.dom={'wrapper':

null,'body':

null,'head':

null,'title':

null,'close_button':

null,'content':

null};

=$('

/*创建外层容器*/this.dom.wrapperclass="dialog_wrapper">

').get(0);

=$('

').get(0);

=$('').get(0);

=$('').get(0);

/*创建对话框主体*/this.dom.body/*创建标题栏*/this.dom.head/*创建标题文本*/

this.dom.title/*创建关闭按钮*/

$('

//this.dom.close_buttonclass="dialog_close_button">close').get(0);

/*创建内容区域*/

this.dom.content=$('

').get(0);

/*组合*/

$(this.dom.head).append('

').append($('').append(this.dom.title)).append(this.dom.close_button);

$(this.dom.body).append(this.dom.head).append(this.dom.content);

$(this.dom.wrapper).append(this.dom.body).append('

both;display:

block;">

');

/*初始化样式*/

$(this.dom.wrapper).css({

'zIndex':

9999,

'display':

'none',

'position':

'absolute'

});

$(this.dom.body).css({

'position':

'relative'

});

$(this.dom.head).css({

'cursor':

'move'

});

$(this.dom.close_button).css({

'position':

'absolute',

'text-indent':

'-9999px',

'cursor':

'pointer',

'overflow':

'hidden'

});

$(this.dom.content).css({

'margin':

'0px',

'padding':

'0px'

});

varself=this;

/*初始化组件事件*/$(this.dom.close_button).click(function(){DialogManager.close(self.id);

});

/*可拖放*/$(this.dom.wrapper).draggable({

'handle':

this.dom.head

});

/*放入文档流*/$(document.body).append(this.dom.wrapper);

},

/*隐藏*/

'hide':

function(){$(this.dom.wrapper).hide();

},

/*显示*/

'show':

function(pos){

if(pos)

{

this.setPosition(pos);

}

/*锁定屏幕*/

ScreenLocker.lock(999);

/*显示对话框*/

$(this.dom.wrapper).show();

},

/*关闭*/

'close':

function(){

if(!

this.onClose())

{

returnfalse;

}

/*关闭对话框*/

$(this.dom.wrapper).remove();

/*解锁屏幕*/

ScreenLocker.unlock();

returntrue;

},

/*对话框标题*/

'setTitle':

function(title){

$(this.dom.title).html(title);

},

/*改变对话框内容*/

'setContents':

function(type,options){

contents=this.createContents(type,options);

if(typeof(contents)=='string')

{

$(this.dom.content).html(contents);

}

else

{

$(this.dom.content).empty();

$(this.dom.content).append(contents);

}

},

/*设置对话框样式*/

'setStyle':

function(style){

if(typeof(style)=='object')

{

/*否则为CSS*/

$(this.dom.wrapper).css(style);

}

else

/*如果是字符串,则认为是样式名*/$(this.dom.wrapper).addClass(style);

}

},

'setWidth':

function(width){

this.setStyle({'width':

width+'px'});

},

'setHeight':

function(

举报
举报
版权申诉
版权申诉
word格式文档无特别注明外均可编辑修改;预览文档经过压缩,下载后原文更清晰! 立即下载
配套讲稿:

如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。

特殊限制:

部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。

关 键  词:
前端 弹出 对话框 js 实现 ajax 交互 剖析
提示  冰豆网所有资源均是用户自行上传分享,仅供网友学习交流,未经上传用户书面授权,请勿作他用。
关于本文
本文标题:前端弹出对话框js实现ajax交互剖析.docx
链接地址:https://www.bdocx.com/doc/8610837.html
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2008-2022 冰点文档网站版权所有

经营许可证编号:鄂ICP备2022015515号-1

收起
展开