---
title: "基于Jquery的dialog插件"
author: "huangro"
date: "2009-06-10T14:23:42Z"
tags: ["Ajax", "CSS", "HTML", "JavaScript", "jQuery"]
slug: "jquery-dialog"
draft: false
lastmod: "2009-06-10T14:25:51Z"
id: 405919
url: "https://huangro.iteye.com/blog/405919"
---

做网站的时候经常需要用到弹出窗体显示一些信息，然而网络上找到的一些JS实现的窗体代码有时候并不能使我们满意，于是乎就自己动手实现了一个基于jquery的dialog插件。因为能力有限，不当之处请指正。 1. dialog.js文件代码 \[code="javascript"] var dialogFirst=true; function dialog(title,content,width,height,cssName){ if(dialogFirst==true){ var temp\_float=new String; temp\_float="

"; temp\_float+="

"; temp\_float+="

关闭

"; temp\_float+="

"; temp\_float+="

"; $("body").append(temp\_float); dialogFirst=false; } $("#floatBox .title span").click(function(){ $("#floatBoxBg").animate({opacity:"0"},"normal",function(){$(this).hide();}); $("#floatBox").animate({top:($(document).scrollTop()-(height=="auto"?300:parseInt(height)))+"px"},"normal",function(){$(this).hide();}); }); $("#floatBox .title h4").html(title); contentType=content.substring(0,content.indexOf(":")); content=content.substring(content.indexOf(":")+1,content.length); switch(contentType){ case "url": var content\_array=content.split("?"); $("#floatBox .content").ajaxStart(function(){ $(this).html("loading..."); }); $.ajax({ type:content\_array\[0], url:content\_array\[1], data:content\_array\[2], error:function(){ $("#floatBox .content").html("error..."); }, success:function(html){ $("#floatBox .content").html(html); } }); break; case "text": $("#floatBox .content").html(content); break; case "id": $("#floatBox .content").html($("#"+content+"").html()); break; case "iframe": $("#floatBox .content").html("