找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1601|回复: 0

[求助] jquery 弹出框一些写法问题

[复制链接]
发表于 2012-11-19 09:23:42 | 显示全部楼层 |阅读模式
  1. 1.<a href="javascript:;"id="test2">confirm</a>
  2. 2.3.4.<script language="javascript"type="text/javascript">
  3. 5.$(document).ready(function(){
  4. 6.     $("#test2").click(function(){
  5. 7.   new $.layerbox({
  6. 8.     'type':"confirm",
  7. 9.     'content':"你确定要删除它吗?",
  8. 10.     'title':"提示",
  9. 11.     'onClose':function(n){ alert(n) }
  10. 12.    })._show();
  11. 13.  });
  12. 14.  });
  13. 15.</script>
复制代码
  1. 1.(function($) {
  2. 2.$.layerbox = function(settings) {
  3. 3.var_this = this;
  4. 4.var_close=$('<span id="layer_close"></span>').click(function(){
  5. 5._this._remove();
  6. 6.});
  7. 7.8._no_btn=$("<button class='layer_no_btn'>取消</button>").click(function(){
  8. 9._this._remove();
  9. 10.});
  10. 11.if(typeof(settings) == 'string') {
  11. 12.varcontent = settings;
  12. 13.settings = {content: content};
  13. 14.}
  14. 15.16.settings.width = (settings.width || 260) > $('body').width() ? $('body').width() : (settings.width || 260);
  15. 17.settings.height = (settings.height || 150) > $('body').height() ? $('body').height() : (settings.height || 150);
  16. 18.settings.title = settings.title || '提示';
  17. 19.settings.content = settings.content || '谢谢使用提示层,请设置要提示的内容!';
  18. 20.this.settings = settings;
  19. 21.22.this.background=$('<div>').css({
  20. 23.'width': $(window).width() + 'px',
  21. 24.'height': $(window).height() + 'px'
  22. 25.}).appendTo('body').addClass('layerop')
  23. 26.27.this.mainWrapBg=$('<div>').css({
  24. 28.'width': settings.width+'px',
  25. 29.'height': settings.height+'px',
  26. 30.'left': ($(window).width() - settings.width) / 2+ 'px',
  27. 31.'top': ($(window).height() - settings.height) / 2 -50+ 'px'
  28. 32.}).appendTo('body').addClass('layerbg')
  29. 33.34.this.mainWrap=$('<div>').css({
  30. 35.'width': settings.width-10+'px',
  31. 36.'height':settings.height-10+'px',
  32. 37.'left': ($(window).width() - (settings.width-10)) / 2+ 'px',
  33. 38.'top': ($(window).height() - (settings.height-10)) / 2 -50+ 'px'
  34. 39.}).appendTo('body').addClass('layerbox')
  35. 40.41.42.switch(settings['type']){
  36. 43.case'loading':
  37. 44.$("<div>", {
  38. 45."class": "layerloading",
  39. 46."style":"text-align:center;padding-top:12px",
  40. 47.html: "<img src='images/layer_loading.gif' style='vertical-align:bottom'/> "+settings['text']
  41. 48.}).appendTo(".layerbox");
  42. 49.break;
  43. 50.case'confirm':
  44. 51.var_yes_btn=$("<button class='layer_yes_btn'>确定</button>").click(function(){
  45. 52.53.54.//请问这里应该怎么写  settings.onClose   值会回调  alert(N)   才能运作啊 55.56.57._this._remove();
  46. 58.});
  47. 59.this.layerTitle=$('<div>',{text:settings.title}).appendTo('.layerbox').addClass('layerTitle')
  48. 60.this.layerTitle.append(_close);
  49. 61.this.layerAlert=$('<div>',{text:settings.content}).appendTo('.layerbox').addClass('layerbox_alert')
  50. 62.this.layerLayerbtn=$('<div>').appendTo('.layerbox').addClass('layer_btn')
  51. 63.this.layerLayerbtn.append(_yes_btn);
  52. 64.break;
  53. 65.}
  54. 66.returnthis;
  55. 67.}
  56. 68./* prototype domready Preceded by new */
  57. 69.$.layerbox.prototype = {
  58. 70._show: function() {
  59. 71.this.background.show();
  60. 72.this.mainWrapBg.show();
  61. 73.returnthis;
  62. 74.},
  63. 75._remove: function() {
  64. 76.$('.layerop,.layerbg,.layerbox').remove()
  65. 77.returnthis;
  66. 78.}
  67. 79.}
  68. 80.81.})(jQuery);
复制代码
就跟一些弹出框一样,点击确定或取消会做一些动作,这里的TRUE   FALSE  是怎么被传回的啊
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|Archiver|手机版|blueidea.com ( 湘ICP备12001430号 )

GMT+8, 2021-1-18 18:35 , Processed in 0.065457 second(s), 8 queries , Gzip On, Memcache On.

Powered by Discuz! X3.2 Licensed

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表