Chinaunix首页 | 论坛 | 博客
  • 博客访问: 193647
  • 博文数量: 124
  • 博客积分: 2111
  • 博客等级: 大尉
  • 技术积分: 1505
  • 用 户 组: 普通用户
  • 注册时间: 2008-02-18 13:40
文章分类

全部博文(124)

文章存档

2011年(5)

2010年(3)

2009年(1)

2008年(115)

我的朋友
最近访客

分类:

2008-02-19 16:24:02

JasperReport 用户指南(转贴) 

一.    JasperReports简介
JasperReports是一个强力的报表产生工具,他有能力描述丰富内容到屏幕上、到打印机或到PDF, HTML, XLS, CSV和XML文件。它完全用Java编写的,并可在各种Java应用(包括J2EE或WEB应用)中用来产生动态内容。它的主要目的是以一种简单而灵活的方式来帮助创建导向的页面。
JasperReports组织根据在一个XML文件中定义的报表设计通过JDBC来接受来自一个关系数据库中的数据. 为了以数据来填充报表,报表设计必须首先被编译。
描述报表设计的XML文件的编译通过执行dori.jasper.engine.JasperManager 类暴露的compileReport()方法。
通过编译,报表设计被装载入一个报表设计对象中,然后系列化并存储在磁盘上(dori.jasper.engine.JasperReport)。当应用程序想以数据来填充特定的报表设计时会使用这个已系列化的对象。事实上,报表设计的编译意指描述报表设计的XML文件中定义的所有Java表达式的编译。为了检查报表设计的一致性,在编译时做各种检验。结果被准备用来填 充报表设计,然后被用来以不同的数据集来产生文档 。
为了填充一个报表设计,可使用由dori.jasper.engine.JasperManager类暴露的 fillReportXXX()方法。这些方法接受作为参数的报表设计对象,或描述特定报表设计对象的文件, 在一个系列化的格式中,和一个从其中接受数据填 充报表的数据库JDBC链接。
结果是一个描述准备用来打印文档的对象(dori.jasper.engine.JasperPrint)并可被以一个系列化格式存储在磁盘上。 为以后使用,或可被分发到打印机,到屏幕或可被转换到一个PDF, HTML, XLS, CSV 或XML文档。
二.    JasperReports快速使用流程
1.    主要类
运行JasperReports 时使用的主要类
dori.jasper.engine.JasperCompileManager
dori.jasper.engine.JasperFillManager
dori.jasper.engine.JasperPrintManager
dori.jasper.engine.JasperExportManager
这些类表现JasperReports引擎的正面(façade), 他们有各种静态方法简化API功能的访问并用来编译一个XML报表设计、填充报表、打印它或输出到PDF, HTML和 XML文件。
dori.jasper.view.JasperViewer
这个可用来观察产生的报表。
dori.jasper.view.JasperDesignViewer
这个可用来观察报表设计。
2. 编译报表设计
报表设计由一个具有在jasperreport.dtd 文件中定义的结构的XML文件来表现。为了根据这样的报表设计来产生报表,需要编译它。
编译可通过使用由dori.jasper.engine.JasperCompileManager 类暴露的compileReportXXX()方法来完成。
当编译一个报表设计时,引擎会创建一个包括所有报表表示式的Java类文件,这个类是使用Java编译器编译并在结果.jasper文件中存储字节码。 
默认情况下,JasperReports使用目前JVM类路径来编译报表文件(java.class.path系统属性)并以目前工作目录作为产生文件的临时存放位置。
为了定制报表编译过程,JasperReports充许通过提供一个值给系统属性jasper.reports.compile.class.path来覆盖默认行为,这将被用报表类编译的类路径,赋一个值给系统属性jasper.reports.compile.temp,这个将被用作临时目录 
XML验证默认是打开的,可通过设定系统属性jasper.reports.compilation.xml.validation 为false来关闭。
如果你想使用一个不同的Java编译器,如jikes,你可以使用jasper.reports.compiler系统属性来提供编译器程序的名字。在你使用jikes情况下,请确信你将rt.jar文件加入到类路径中,可通过上面提及的系统属性 jasper.reports.compile.class.path。 
You can see some of those in action in the supplied "webapp" samples. Check the jsp/compile.jsp and WEB-INF/classes/servlets/CompileServlet.java files.
3. 观察报表设计 
报表设计可通过使用dori.jasper.view.JasperDesignViewer应用程序来察看。在其main()方法中,它接收那些包括报表设计的文件的名字来观看。这可以是XML文件或编译过的报表设计。 
4. 填充报表 
一个编译过的报表设计可通过调用dori.jasper.engine.JasperFillManager 类的fillReportXXX()方法来产生报表。
5. 观看报表 
产生的报表可通使用dori.jasper.view.JasperViewer应用来观看。在其main()方法中它接受包括报表的文件的名字来观看。
6. 打印报表
产生的报表可使用doriJasper.engine.JasperPrintManager 类暴露的静态方法printReport(), printPage()或printPages()来打印。
7.导出到PDF, HTML 或XML格式
在已经填充一个报表后,我们也可以通过使用dori.jasper.engine.JasperExportManager类的exportReportXXX()方法来以 PDF, HTML或XML格式导出它。
三.    技术指南简述
1.报表设计
一个报表设计描述一个被JasperReports引擎用来分发动态内容到打印机,到屏幕或到WEB的模板。存储在数据库中的数据根据报表设计被组织达到准备到打印,页面导向文档。
报表设计是在XML文件中定义并且必有一个特别的结构。此结构是在一个由JasperReports 引擎一起提供的DTD文件中声明的(XML类型定义文件jasperreport.dtd)。然后编译XML文件,为了在后面的报表填充操作中使用他们。
为了创建一个简单的报表设计,我们不得不编辑一个有以下结构的XML文件:
 
""> 
 
... 

2.参数
参数是传入到报表填充操作的对象引用
参数可的构造SQL查询
3.数据源 
JasperReports使用一个叫JRDataSource的接口来支持各种类型的数据源
4.字段
报表字段代表从数据源映射数据到报表产生程序的唯一途径
5.表达式
表达式是JasperReports的强大特点,它们可被声明的报表变量使用来执行各种计算。
6.变量
报表变量是才一个表达式开始时建立的特殊的对象。
变量可以在相应的表达式中执行内置类型的计算,如:count,sum,average,lowest,highest等
7.报表区
当我们建立一个报表设计时,我们需要定义报表区的内容和布局。报表设计的整个结构基于以下报表区, <pageHeader>, <columnHeader>, <groupHeader>, <detail>, <groupFooter>, <columnFoter>, <pageFooter>, <summary>.<BR>8.组<BR>组代表了在报表上组织数据的一个灵活的方式,当我们填充一个报表时,JasperReports引擎可字段检测组表达式<groupFooter> 和 <groupHeader>等是否完整。<BR>9.字体和Unicode支持<BR>你可以用任何语言来创建你的报表。<BR>10. Scriptlets<BR>Scriptlets是java代码序列,在每次报表事件发生时被执行。通过 scriptlets,用户可以影响被报表变量存储的值。<BR>当我们创建一个JasperReports scriptlet类时,开发者要实现或重载几个方法,象:beforeReportInit(), afterReportInit(), beforePageInit(), afterPageInit(), beforeGroupInit(), afterGroupInit()等,这些方法当填充报表时在适当的时候被报表引擎调用。<BR>11.子报表<BR>子报表是报表产生工具的重要特征,它允许更复杂报表的创建并简化设计工作。<BR>子报表在创建主从报表时非常有用。<BR></P> <P>1  首先看看<BR>   上的三篇<BR>   iReport和Jasperreport整合开发报表向导(一)(二)(三)<BR>   看完理解并自己运行一下,OK,你入门了<BR>2  去找一份TheJasperReportsUltimateGuide.1.0.pdf,看完之后你就能<BR>   了解JasperReport生成的基本过程及原理<BR>3  当然是Java研究的这个论坛<BR>   <BR>   多往后翻翻看看帖子,很多你要问的问题都能找到答案,还有好几篇前辈的理会等等 <BR>   都是宝贵的经验<BR>4  JasperReport最好的资料是什么??<BR>   解压jasperreports-0.5.0-project.zip 后<BR>   目录jasperreports\demo\samples下的例子,看看这些例子是你关于这个报表工具提升 <BR>   能力的最好最快的方式,下面我简要说一下各个例子说的是什么以及有什么用<BR>    alterdesign 该例子演示了报表编译后,在报表展现的时候如何动态的控制其中的元素<BR>                比如让某一个矩形变色或其他<BR>    antcompile  演示如何让 ant 来编译<BR>    chart       演示了如何在报表中添加图像,JasperReport是用Scriptlet的方式<BR>                往报表中添加图像,而Scriptlet是调用也是开源的jfreechart的Api来<BR>                生成图形,去jfreechart看一下,该工具能的图形生成能力也很强<BR>    datasource  演示了如何在报表中使用各种数据源,能够使用beanarray<BR>                beancollection,也可以用自定义的数据源,只要继承了JRDataSource的<BR>                两个接口,这个能给用户提供非常大的灵活性,报表的数据不用局限于一<BR>                条Sql语句,也可以使用存储过程,对生成报表中的数据也可以排序,二<BR>                次检索,等等<BR>    fonts       各种字体的演示<BR>    horizontal  演示了水平分栏的报表,演示报表中分了三栏,其中还用到了<BR>                textFieldExpression,就像if语句的效果来选择输出的内容<BR>    hyperlink   演示了各种样式的链接<BR>    images      演示了如何在报表中加入图像以及图像的显示方式<BR>    jasper      演示了分组分栏的报表,演示中用了2次group<BR>    jcharts     演示了调用另一个开源的API jcharts来往报表中加入分析图形,原理同<BR>                上chart,如果jfreechart都还不能满足你分析图形的要求,那到jcharts<BR>                里找找看吧,说不定有<BR>    landscape   演示横向的报表<BR>    nopagebreak 演示比如在IE中不分页的方式打印出报表的内容,通过这个演示也可以<BR>                了解报表输出如何配置参数<BR>    noreport    演示了如何直接通过java程序生成JasperPrint对象来输出<BR>    noxmldesign 演示了如何直接通过java程序生成JasperDesign对象来动态的生成报<BR>                表,根据这个例子,用户可以作出自定义选列的报表,当然比较麻烦,<BR>                而且肯定自己要补充他的API库<BR>                (JasperReport真是强大啊,呵呵)    <BR>    pdfencrypt  演示了pdf的输出方式,可以给pdf文件加密码,其实就是pdf输出方式的<BR>                参数配置,具体有那些参数可配置,去看看API吧<BR>    printservice演示了如何直接打印报表<BR>    query       演示了如何让查询的sql动态起来,比如你可以通过一个Jsp页面传<BR>                报表的sql的where条件,order条件,甚至整个sql语句<BR>    rotation    演示了文字纵向显示的报表<BR>    scriptlet   演示了如何继承JRDefaultScriptlet,并加入自己的处理语句,这个功能<BR>                可是很强大的哦,看看这些接口<BR>                beforeReportInit()  afterReportInit()  beforePageInit()<BR>                afterPageInit()  beforeColumnInit()  afterColumnInit() <BR>                beforeGroupInit(String groupName)<BR>                afterGroupInit(String groupName)  <BR>                看看这些名字就知道你能完成那些功能,比如显示一列数据后,马上跟<BR>                上该列数据的分析图形,当然你也可以加上自己的方法并在报表中调用<BR>    shapes      演示了JasperReport中自带的图形,及能配置的参数<BR>                当然你也能继承或者覆写JasperReport中的Api生成你要的图形,<BR>    stretch     演示了如何处理报表中数据拉伸以及带来周围的线及框的拉伸,<BR>                你能了解到虽然黑框式表格不是JasperReport中缺省的展现方式,<BR>                但在JasperReport中不难实现<BR>    subreport   演示了子报表,还告诉你一个报表中可以有n个子报表,子报表中还可以<BR>                嵌套子报表<BR>    tableofcontents  演示了如何生成一个有目录的,复杂的报表<BR>    unicode     演示了各种 字符编码<BR>    webapp      演示了如何把报表放到一个JavaWeb项目中,可以用Jsp Servlet<BR>                applet,笔者做了一个<BR>                有参数页面,可以选择html pdf applet输出方式的报表,有兴趣的 <BR>                我可以在后面放上代码<BR>5  比上面更好的资料是什么,就是JasperReport的源代码,看懂源代码,JasperReport<BR>   就是在你脑子里的了,你想干什么都行了,优化代码,覆写,继承他的类,实现个性<BR>   化的功能,甚至你可以参考他的思想,升华一下,做一个你自己的报表<BR></P> <DIV></DIV> </div> <!-- <div class="Blog_con3_1">管理员在2009年8月13日编辑了该文章文章。</div> --> <div class="Blog_con2_1 Blog_con3_2"> <div> <!--<img src="/image/default/tu_8.png">--> <!-- JiaThis Button BEGIN --> <div class="bdsharebuttonbox"><A class=bds_more href="#" data-cmd="more"></A><A class=bds_qzone title=分享到QQ空间 href="#" data-cmd="qzone"></A><A class=bds_tsina title=分享到新浪微博 href="#" data-cmd="tsina"></A><A class=bds_tqq title=分享到腾讯微博 href="#" data-cmd="tqq"></A><A class=bds_renren title=分享到人人网 href="#" data-cmd="renren"></A><A class=bds_weixin title=分享到微信 href="#" data-cmd="weixin"></A></div> <script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script> <!-- JiaThis Button END --> </div> 阅读(967) | 评论(0) | 转发(0) | <div class="HT_line3"></div> </div> <div class="Blog_con3_3"> <div><span id='digg_num'>0</span><a href="javascript:void(0)" id='digg' bid='1581403' url='/blog/digg.html' ></a></div> <p>上一篇:<a href="/uid-20669118-id-1581402.html">网摘(关于木马) ^_^</a></p> <p>下一篇:<a href="/uid-20669118-id-1581404.html">用Jasper做报表的一个例子</a></p> </div> </div> <!-- <div class="Blog_con3_4 Blog_con3_5"> <div class="Blog_tit2 Blog_tit7">热门推荐</div> <ul> <li><a href="" title="" target='blank' ></a></li> </ul> </div> --> </div> </div> <div class="Blog_right1_7" id='replyList'> <div class="Blog_tit3">给主人留下些什么吧!~~</div> <!--暂无内容--> <!-- 评论分页--> <div class="Blog_right1_6 Blog_right1_12"> </div> <!-- 评论分页--> <div class="Blog_right1_10" style="display:none"> <div class="Blog_tit3">评论热议</div> <!--未登录 --> <div class="Blog_right1_8"> <div class="nologin_con1"> 请登录后评论。 <p><a href="http://account.chinaunix.net/login" onclick="link(this)">登录</a> <a href="http://account.chinaunix.net/register?url=http%3a%2f%2fblog.chinaunix.net">注册</a></p> </div> </div> </div> <div style="text-align:center;margin-top:10px;"> <script type="text/javascript" smua="d=p&s=b&u=u3118759&w=960&h=90" src="//www.nkscdn.com/smu0/o.js"></script> </div> </div> </div> </div> <input type='hidden' id='report_url' value='/blog/ViewReport.html' /> <script type="text/javascript"> //测试字符串的长度 一个汉字算2个字节 function mb_strlen(str) { var len=str.length; var totalCount=0; for(var i=0;i<len;i++) { var c = str.charCodeAt(i); if ((c >= 0x0001 && c <= 0x007e) || (0xff60<=c && c<=0xff9f)) { totalCount++; }else{ totalCount+=2; } } return totalCount; } /* var Util = {}; Util.calWbText = function (text, max){ if(max === undefined) max = 500; var cLen=0; var matcher = text.match(/[^\x00-\xff]/g), wlen = (matcher && matcher.length) || 0; //匹配url链接正则 http://*** var pattern = /http:\/\/([\w-]+\.)+[\w-]+(\/*[\w-\.\/\?%&=][^\s^\u4e00-\u9fa5]*)?/gi; //匹配的数据存入数组 var arrPt = new Array(); var i = 0; while((result = pattern.exec(text)) != null){ arrPt[i] = result[0]; i++; } //替换掉原文本中的链接 for(var j = 0;j<arrPt.length;j++){ text = text.replace(arrPt[j],""); } //减掉链接所占的长度 return Math.floor((max*2 - text.length - wlen)/2 - 12*i); }; */ var allowComment = '0'; //举报弹出层 function showJuBao(url, cid){ $.cover(false); asyncbox.open({ id : 'report_thickbox', url : url, title : '举报违规', width : 378, height : 240, scroll : 'no', data : { 'cid' : cid, 'idtype' : 2 , 'blogurl' : window.location.href }, callback : function(action){ if(action == 'close'){ $.cover(false); } } }); } $(function(){ //创建管理员删除的弹出层 $('#admin_article_del').click(function(){ $.cover(false); asyncbox.open({ id : 'class_thickbox', html : '<div class="HT_layer3_1"><ul><li class="HT_li1">操作原因:<select class="HT_sel7" id="del_type" name="del_type"><option value="广告文章">广告文章</option><option value="违规内容">违规内容</option><option value="标题不明">标题不明</option><option value="文不对题">文不对题</option></select></li><li class="HT_li1" ><input class="HT_btn4" id="admin_delete" type="button" /></li></ul></div>', title : '选择类型', width : 300, height : 150, scroll : 'no', callback : function(action){ if(action == 'close'){ $.cover(false); } } }); }); $('#admin_delete').live('click' , function(){ ///blog/logicdel/id/3480184/url/%252Fblog%252Findex.html.html var type = $('#del_type').val(); var url = '/blog/logicdel/id/1581403/url/%252Fuid%252F20669118.html.html'; window.location.href= url + '?type=' + type; }); //顶 js中暂未添加&过滤 $('#digg').live('click' , function(){ if(isOnLine == '' ) { //showErrorMsg('登录之后才能进行此操作' , '消息提示'); showErrorMsg('操作失败,您需要先登录!', '消息提示', 'http://account.chinaunix.net/login'); return false; } var bid = $('#digg').attr('bid'); var url = $('#digg').attr('url'); var digg_str = $.cookie('digg_id'); if(digg_str != null) { var arr= new Array(); //定义一数组 arr = digg_str.split(","); //字符分割 for( i=0 ; i < arr.length ; i++ ) { if(bid == arr[i]) { showErrorMsg('已经赞过该文章', '消息提示'); return false; } } } $.ajax({ type:"POST", url:url, data: { 'bid' : bid }, dataType: 'json', success:function(msg){ if(msg.error == 0) { var num = parseInt($('#digg_num').html(),10); num += 1; $('#digg_num').html(num); $('#digg').die(); if(digg_str == null) { $.cookie('digg_id', bid, {expires: 30 , path: '/'}); } else { $.cookie('digg_id', digg_str + ',' + bid, {expires: 30 , path: '/'}); } showSucceedMsg('谢谢' , '消息提示'); } else if(msg.error == 1) { //showErrorMsg(msg.error_content , '消息提示'); showErrorMsg('操作失败,您需要先登录!', '消息提示', 'http://account.chinaunix.net/login'); } else if(msg.error == 2) { showErrorMsg(msg.error_content , '消息提示'); } } }); }); //举报弹出层 /*$('.box_report').live('click' , function(){ if(isOnLine == '' ) { //showErrorMsg('登录之后才能进行此操作' , '消息提示'); showErrorMsg('操作失败,您需要先登录!', '消息提示', 'http://account.chinaunix.net/login'); return false; } var url = $('#report_url').val(); var cid = $(this).attr('cid'); $.cover(false); asyncbox.open({ id : 'report_thickbox', url : url, title : '举报违规', width : 378, height : 240, scroll : 'no', data : { 'cid' : cid, 'idtype' : 2 }, callback : function(action){ if(action == 'close'){ $.cover(false); } } }); });*/ //评论相关代码 //点击回复显示评论框 $('.Blog_a10').live('click' , function(){ if(isOnLine == '' ) { //showErrorMsg('登录之后才能进行此操作' , '消息提示'); showErrorMsg('操作失败,您需要先登录!', '消息提示', 'http://account.chinaunix.net/login'); return false; } if(allowComment == 1) { showErrorMsg('该博文不允许评论' , '消息提示'); return false; } var tid = $(this).attr('toid');//留言作者id var bid = $(this).attr('bid');//blogid var cid = $(this).attr('cid');//留言id var tname = $(this).attr('tname'); var tpl = '<div class="Blog_right1_9">'; tpl += '<div class="div2">'; tpl += '<textarea name="" cols="" rows="" class="Blog_ar1_1" id="rmsg">文明上网,理性发言...</textarea>'; tpl += '</div>'; tpl += '<div class="div3">'; tpl += '<div class="div3_2"><a href="javascript:void(0);" class="Blog_a11" id="quota_sbumit" url="/Comment/PostComment.html" tid="'+tid+'" bid="'+bid+'" cid="'+cid+'" tname="'+tname+'" ></a><a href="javascript:void(0)" id="qx_comment" class="Blog_a12"></a></div>'; tpl += '<div class="div3_1"><a href="javascript:void(0);" id="mface"><span></span>表情</a></div>'; tpl += '<div class="clear"></div>'; tpl += '</div>'; tpl += '</div>'; $('.z_move_comment').html(''); $(this).parents('.Blog_right1_8').find('.z_move_comment').html(tpl).show(); }); //引用的评论提交 $('#quota_sbumit').live('click' , function(){ if(isOnLine == '' ) { //showErrorMsg('登录之后才能进行此操作' , '消息提示'); showErrorMsg('操作失败,您需要先登录!', '消息提示', 'http://account.chinaunix.net/login'); return false; } var bid = $(this).attr('bid'); var tid = $(this).attr('tid');//被引用人的id var qid = $(this).attr('cid');//引用的id var url = $(this).attr('url'); var text = $('#rmsg').val(); var tname = $(this).attr('tname'); if(text == '' || text=='文明上网,理性发言...') { showErrorMsg('评论内容不能为空!' , '消息提示'); return false; } else { if(mb_strlen(text) > 1000){ showErrorMsg('评论内容不能超过500个汉字' , '消息提示'); return false; } } $.ajax({ type: "post", url: url , data: {'bid': bid , 'to' : tid , 'qid' : qid , 'text': text , 'tname' : tname }, dataType: 'json', success: function(data){ if(data.code == 1){ var tpl = '<div class="Blog_right1_8">'; tpl+= '<div class="Blog_right_img1"><a href="' +data.info.url+ '" >' + data.info.header + '</a></div>'; tpl+= '<div class="Blog_right_font1">'; tpl+= '<p class="Blog_p5"><span><a href="' +data.info.url+ '" >' + data.info.username + '</a></span>' + data.info.dateline + '</p>'; tpl+= '<p class="Blog_p7"><a href="' + data.info.quota.url + '">' + data.info.quota.username + '</a>:'+ data.info.quota.content + '</p>'; tpl+= '<p class="Blog_p8">' + data.info.content + '</p><span class="span_text1"><a href="javascript:void(0);" class="Blog_a10" toid=' + data.info.fuid + ' bid=' + data.info.bid + ' cid=' + data.info.cid + ' tname = ' + data.info.username + ' >回复</a> |  <a class="comment_del_mark" style="cursor:pointer" url="' + data.info.delurl + '" >删除</a> |  <a href="javascript:showJuBao(\'/blog/ViewReport.html\','+data.info.cid+')" class="box_report" cid="' + data.info.cid + '" >举报</a></span></div>'; tpl+= '<div class="z_move_comment" style="display:none"></div>'; tpl+= '<div class="Blog_line1"></div></div>'; $('#replyList .Blog_right1_8:first').before(tpl); $('.z_move_comment').html('').hide(); } else if(data.code == -1){ //showErrorMsg(data.info , '消息提示'); showErrorMsg('操作失败,您需要先登录!', '消息提示', 'http://account.chinaunix.net/login'); } }, error: function(){//请求出错处理 } }); }); //底部发表评论 $('#submitmsg').click(function(){ if(allowComment == 1) { showErrorMsg('该博文不允许评论' , '消息提示'); return false; } var bid = $(this).attr('bid'); var toid = $(this).attr('toid'); var text = $('#reply').val(); var url = $(this).attr('url'); if(text == '' || text=='文明上网,理性发言...') { showErrorMsg('评论内容不能为空!' , '消息提示'); return false; } else { if(mb_strlen(text) > 1000){ showErrorMsg('评论内容不能超过500个汉字' , '消息提示'); return false; } } $.ajax({ type: "post", url: url , data: {'bid': bid , 'to' : toid ,'text': text}, dataType: 'json', success: function(data){ if(data.code == 1) { var tpl = '<div class="Blog_right1_8">'; tpl += '<div class="Blog_right_img1"><a href="' +data.info.url+ '" >' + data.info.header + '</a></div>'; tpl += '<div class="Blog_right_font1">'; tpl += '<p class="Blog_p5"><span><a href="' +data.info.url+ '" >' + data.info.username + '</a></span>' + data.info.dateline + '</p>'; tpl += '<p class="Blog_p6">' + data.info.content + '</p>'; tpl += '<div class="div1"><a href="javascript:void(0);" class="Blog_a10" toid=' + data.info.fuid + ' bid=' + data.info.bid + ' cid=' + data.info.cid + '>回复</a> |  <a class="comment_del_mark" style="cursor:pointer" url="' + data.info.delurl + '">删除</a> |  <a href="javascript:showJuBao(\'/blog/ViewReport.html\','+data.info.cid+')" class="box_report" cid="' + data.info.cid + '">举报</a></div>'; tpl += '<div class="z_move_comment" style="display:none"></div>'; tpl += '</div><div class="Blog_line1"></div></div>'; $('.Blog_tit3:first').after(tpl); $('#reply').val('文明上网,理性发言...'); } else if(data.code == -1) { showErrorMsg(data.info , '消息提示'); } }, error: function(){//请求出错处理 } }); }); //底部评论重置 $('#reset_comment').click(function(){ $('#reply').val('文明上网,理性发言...'); }); //取消回复 $('#qx_comment').live('click' , function(){ $('.z_move_comment').html('').hide(); }); $('#rmsg, #reply').live({ focus:function(){ if($(this).val() == '文明上网,理性发言...'){ $(this).val(''); } }, blur:function(){ if($(this).val() == ''){ $(this).val('文明上网,理性发言...'); } } }); //删除留言确认 $('.comment_del_mark').live('click' , function(){ var url = $(this).attr('url'); asyncbox.confirm('删除留言','确认', function(action){ if(action == 'ok') { location.href = url; } }); }); //删除时间确认 $('.del_article_id').click(function(){ var delurl = $(this).attr('delurl'); asyncbox.confirm('删除文章','确认', function(action){ if(action == 'ok') { location.href = delurl; } }); }); /* //字数限制 $('#rmsg, #reply').live('keyup', function(){ var id = $(this).attr('id'); var left = Util.calWbText($(this).val(), 500); var eid = '#errmsg'; if(id == 'reply') eid = '#rerrmsg'; if (left >= 0) $(eid).html('您还可以输入<span>' + left + '</span>字'); else $(eid).html('<font color="red">您已超出<span>' + Math.abs(left) + '</span>字 </font>'); }); */ //加载表情 $('#face').qqFace({id : 'facebox1', assign : 'reply', path : '/image/qqface/'}); $('#mface').qqFace({id : 'facebox', assign : 'rmsg', path:'/image/qqface/'}); /* $('#class_one_id').change(function(){ alert(123213); var id = parseInt($(this).val() , 10); if(id == 0) return false; $('.hidden_son_class span').each(function( index , dom ){ if( dom.attr('cid') == id ) { } }); }); */ //转载文章 var turn_url = "/blog/viewClassPart.html"; $('#repost_bar').click(function(){ if(isOnLine == '' ) { //showErrorMsg('登录之后才能进行此操作' , '消息提示'); showErrorMsg('操作失败,您需要先登录!', '消息提示', 'http://account.chinaunix.net/login'); return false; } var id = $(this).attr('bid'); asyncbox.open({ id : 'turn_class_thickbox', url : turn_url, title : '转载文章', width : 330, height : 131, scroll : 'no', data : { 'id' : id }, callback : function(action){ if(action == 'close'){ $.cover(false); } } }); }); /* //转发文章 $('#repost_bar').live('click' , function(){ if(isOnLine == '' ) { //showErrorMsg('登录之后才能进行此操作' , '消息提示'); showErrorMsg('操作失败,您需要先登录!', '消息提示', 'http://account.chinaunix.net/login'); return false; } var bid = $(this).attr('bid'); var url = $(this).attr('url'); asyncbox.confirm('转载文章','确认', function(action){ if(action == 'ok'){ $.ajax({ type:"POST", url:url, data: { 'bid' : bid }, dataType: 'json', success:function(msg){ if(msg.error == 0){ showSucceedMsg('转发成功!', '消息提示'); }else if(msg.error == 1){ //location.href = '/index.php?r=site/login'; showErrorMsg('操作失败,您需要先登录!', '消息提示', 'http://account.chinaunix.net/login'); }else{ showErrorMsg(msg.error_content, '消息提示'); } } }); } }); }); */ }); </script> <!--该部分应该放在输出代码块的后面才起作用 --> <script type="text/javascript"> SyntaxHighlighter.autoloader( 'applescript /highlight/scripts/shBrushAppleScript.js', 'actionscript3 as3 /highlight/scripts/shBrushAS3.js', 'bash shell /highlight/scripts/shBrushBash.js', 'coldfusion cf /highlight/scripts/shBrushColdFusion.js', 'cpp c /highlight/scripts/shBrushCpp.js', 'c# c-sharp csharp /highlight/scripts/shBrushCSharp.js', 'css /highlight/scripts/shBrushCss.js', 'delphi pascal /highlight/scripts/shBrushDelphi.js', 'diff patch pas /highlight/scripts/shBrushDiff.js', 'erl erlang /highlight/scripts/shBrushErlang.js', 'groovy /highlight/scripts/shBrushGroovy.js', 'java /highlight/scripts/shBrushJava.js', 'jfx javafx /highlight/scripts/shBrushJavaFX.js', 'js jscript javascript /highlight/scripts/shBrushJScript.js', 'perl pl /highlight/scripts/shBrushPerl.js', 'php /highlight/scripts/shBrushPhp.js', 'text plain /highlight/scripts/shBrushPlain.js', 'py python /highlight/scripts/shBrushPython.js', 'ruby rails ror rb /highlight/scripts/shBrushRuby.js', 'scala /highlight/scripts/shBrushScala.js', 'sql /highlight/scripts/shBrushSql.js', 'vb vbnet /highlight/scripts/shBrushVb.js', 'xml xhtml xslt html /highlight/scripts/shBrushXml.js' ); SyntaxHighlighter.all(); function code_hide(id){ var code = document.getElementById(id).style.display; if(code == 'none'){ document.getElementById(id).style.display = 'block'; }else{ document.getElementById(id).style.display = 'none'; } } </script> <!--回顶部js2011.12.30--> <script language="javascript"> lastScrollY=0; function heartBeat(){ var diffY; if (document.documentElement && document.documentElement.scrollTop) diffY = document.documentElement.scrollTop; else if (document.body) diffY = document.body.scrollTop else {/*Netscape stuff*/} percent=.1*(diffY-lastScrollY); if(percent>0)percent=Math.ceil(percent); else percent=Math.floor(percent); document.getElementById("full").style.top=parseInt(document.getElementById("full").style.top)+percent+"px"; lastScrollY=lastScrollY+percent; if(lastScrollY<200) { document.getElementById("full").style.display="none"; } else { document.getElementById("full").style.display="block"; } } var gkuan=document.body.clientWidth; var ks=(gkuan-960)/2-30; suspendcode="<div id=\"full\" style='right:-30px;POSITION:absolute;TOP:500px;z-index:100;width:26px; height:86px;cursor:pointer;'><a href=\"javascript:void(0)\" onclick=\"window.scrollTo(0,0);\"><img src=\"\/image\/top.png\" /></a></div>" document.write(suspendcode); window.setInterval("heartBeat()",1); </script> <!-- footer --> <div class="Blog_footer" style='clear:both'> <div><a href="http://www.chinaunix.net/about/index.shtml" target="_blank" rel="nofollow">关于我们</a> | <a href="http://www.it168.com/bottomfile/it168.shtml" target="_blank" rel="nofollow">关于IT168</a> | <a href="http://www.chinaunix.net/about/connect.html" target="_blank" rel="nofollow">联系方式</a> | <a href="http://www.chinaunix.net/about/service.html" target="_blank" rel="nofollow">广告合作</a> | <a href="http://www.it168.com//bottomfile/flgw/fl.htm" target="_blank" rel="nofollow">法律声明</a> | <a href="http://account.chinaunix.net/register?url=http%3a%2f%2fblog.chinaunix.net" target="_blank" rel="nofollow">免费注册</a> <p>Copyright 2001-2010 ChinaUnix.net All Rights Reserved 北京皓辰网域网络信息技术有限公司. 版权所有 </p> <div>感谢所有关心和支持过ChinaUnix的朋友们 <p><a href="http://beian.miit.gov.cn/">16024965号-6 </a></p> </div> </div> </div> </div> <script language="javascript"> //全局错误提示弹出框 function showErrorMsg(content, title, url){ var url = url || ''; var title = title || '消息提示'; var html = ''; html += '<div class="HT_layer3_1 HT_layer3_2"><ul><li><p><span class="login_span1"></span>' + content + '</p></li>'; if(url == '' || url.length == 0){ html += '<li class="HT_li1"><input type="button" class="HT_btn2" onclick=\'close_windows("error_msg")\'></li>'; } else { html += '<li class="HT_li1"><input type="button" class="login_btn1" onclick="location.href=\'' + url + '\'"></li>'; } html += '</ul></div>'; $.cover(true); asyncbox.open({ id: 'error_msg', title : title, html : html, 'callback' : function(action){ if(action == 'close'){ $.cover(false); } } }); } //全局正确提示 function showSucceedMsg(content, title , url ){ var url = url || ''; var title = title || '消息提示'; var html = ''; html += '<div class="HT_layer3_1 HT_layer3_2"><ul><li><p><span class="login_span2"></span>' + content + '</p></li>'; if(url == '' || url.length == 0){ html += '<li class="HT_li1"><input type="button" class="HT_btn2" onclick=\'close_windows("error_msg")\'></li>'; } else { html += '<li class="HT_li1"><input type="button" class="HT_btn2" onclick="location.href=\'' + url + '\'"></li>'; } html += '</ul></div>'; $.cover(true); asyncbox.open({ id: 'error_msg', title : title, html : html, 'callback' : function(action){ if(action == 'close'){ $.cover(false); } } }); } //关闭指定id的窗口 function close_windows(id){ $.cover(false); $.close(id); } //公告 var tID; var tn; // 高度 var nStopTime = 5000; // 不同行间滚动时间隔的时间,值越小,移动越快 var nSpeed = 50; // 滚动时,向上移动一像素间隔的时间,值越小,移动越快 var isMove = true; var nHeight = 25; var nS = 0; var nNewsCount = 3; /** * n 用于表示是否为第一次运行 **/ function moveT(n) { clearTimeout(tID) var noticev2 = document.getElementById("noticev2") nS = nSpeed; // 只在第一次调用时运行,初始化环境(有没有参数) if (n) { // 设置行高 noticev2.style.lineHeight = nHeight + "px"; // 初始化显示位置 tn = 0; // 刚进入时在第一行停止时间 nS = nStopTime; } // 判断鼠标是否指向层 if (isMove) { // 向上移动一像素 tn--; // 如果移动到最下面一行了,则移到顶行 if (Math.abs(tn) == nNewsCount * nHeight) { tn = 0; } // 设置位置 noticev2.style.marginTop = tn + "px"; // 完整显示一行时,停止一段时间 if (tn % nHeight == 0) { nS = nStopTime; } } tID = setTimeout("moveT()", nS); } moveT(1); // 此处可以传入任何参数 </script> <script type="text/javascript"> // var _gaq = _gaq || []; // _gaq.push(['_setAccount', 'UA-20237423-2']); // _gaq.push(['_setDomainName', '.chinaunix.net']); // _gaq.push(['_trackPageview']); // // (function() { // var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; // ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; // var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); // })(); </script> <script type="text/javascript"> var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://"); document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3F0ee5e8cdc4d43389b3d1bfd76e83216b' type='text/javascript'%3E%3C/script%3E")); function link(t){ var href= $(t).attr('href'); href+="?url="+encodeURIComponent(location.href); $(t).attr('href',href); //setCookie("returnOutUrl", location.href, 60, "/"); } </script> <script type="text/javascript" src="/js/jquery.qqFace.js"></script> </body> </html>