js问题

------------------------------------------------------------------------------------------------


这是html文件

View Code
  1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2 <html>
  3     <head>
  4         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5         <style type="text/css">
  6             body{margin:0;padding:0;font-size:12px;background:white;}
  7             h3{font-size:16px;color:red;}
  8             label{display:inline-block;width:100px;text-align:right;}
  9             textarea{width:90%;margin:0 auto;height:300px;display:block;}
 10         </style>
 11     </head>
 12     <body>
 13         <h3>引擎POST数据测试页面</h3>
 14         <form action="report.preview.pt" method="post" id="form">
 15             <label>页面ID:</label>
 16             <input type="text" name="pageid" id="pageid" value="1" />
 17             <br/><br/>
 18             <label>配置内容:</label>
 19             <textarea id="content" name="content">
 20 {
 21     "exterior-dir":"C:\\Documents and Settings\\Administrator\\桌面\\报表\\images",
 22     "exterior-database":{
 23         "driver-url":"jdbc:mysql://127.0.0.1/new?characterEncoding=UTF-8",
 24         "driver-class":"com.mysql.jdbc.Driver",
 25         "user":"root",
 26         "password":"123"
 27     },
 28     "content":[{
 29         "name":"提交的一级菜单",
 30         "childs":[{
 31             "id":1,
 32             "name":"提交的二级菜单",
 33             "default":true,
 34             "page_header":{
 35                 "text":"MatriXay Web应用安全评估报告",
 36                 "text-decoration":"",
 37                 "font-weight":"",
 38                 "font-size":"20px",
 39                 "color":"#0000FF",
 40                 "items":[[{
 41                     "type":"image",
 42                     "value":"c:/flag.jpg",
 43                     "width":"auto",
 44                     "height":"auto"
 45                 },{
 46                     "type":"text",
 47                     "color":"#000000",
 48                     "font-size":"12px",
 49                     "value":"MatriXay Web应用安全评估报告",
 50                     "space-left":"28"
 51                 }]]
 52             },
 53             "page_footer":{
 54                 "text":"杭州安恒信息技术有限公司",
 55                 "text-decoration":"",
 56                 "font-weight":"",
 57                 "font-size":"12px",
 58                 "color":"#0000FF",
 59                 "items":[[{
 60                     "type":"text",
 61                     "value":"杭州安恒信息技术有限公司",
 62                     "text-decoration":"",
 63                     "font-weight":"",
 64                     "font-size":"12px",
 65                     "color":"#000000",
 66                     "space-left":"0",
 67                     "space-right":"0"
 68                 }],[{
 69                     "type":"line",
 70                     "font-size":"12px",
 71                     "num":"60"
 72                 }],[{
 73                     "type":"text",
 74                     "value":"2013/1/18  12:56:22    powered by",
 75                     "text-decoration":"",
 76                     "font-weight":"",
 77                     "font-size":"12px",
 78                     "color":"#000000",
 79                     "space-right":"2"
 80                 },{
 81                     "type":"text",
 82                     "value":"DBAPPSecurity Ltd.",
 83                     "text-decoration":"",
 84                     "font-weight":"",
 85                     "font-size":"12px",
 86                     "color":"#F1A572",
 87                     "space-left":"4"
 88                 },{
 89                     "type":"text",
 90                     "value":"第 ",
 91                     "text-decoration":"",
 92                     "font-weight":"bold",
 93                     "font-size":"12px",
 94                     "color":"#000000",
 95                     "space-left":"14"
 96                 },{
 97                     "type":"currPage",
 98                     "text-decoration":"underline",
 99                     "font-weight":"bold",
100                     "font-size":"12px",
101                     "color":"#FF0000"
102                 },{
103                     "type":"text",
104                     "value":"页,共 ",
105                     "text-decoration":"",
106                     "font-weight":"bold",
107                     "font-size":"12px",
108                     "color":"#000000"
109                 },{
110                     "type":"totalPage"
111                 },{
112                     "type":"text",
113                     "value":"页",
114                     "text-decoration":"",
115                     "font-weight":"bold",
116                     "font-size":"12px",
117                     "color":"#000000",
118                     "space-left":"1"
119                 }]]
120             },
121             "items":[{
122                 "type":"title",
123                 "title":"frame配置示例",
124                 "margin-top":"30px"
125             },{
126                 "type":"frame",
127                 "title":"配置标题",
128                 "margin-top":"20px",
129                 "margin-bottom":"20px",
130                 "width":"90%",
131                 "items":[{
132                     "type":"frame",
133                     "title":"可无限级嵌套",
134                     "items":[{
135                         "type":"text",
136                         "text-align":"center",
137                         "margin-top":"20px",
138                         "margin-bottom":"20px",
139                         "items":[{
140                             "type":"image",
141                             "value":"user_orange.png",
142                             "margin-left":"5px",
143                             "margin-right":"5px"
144                         },{
145                             "type":"text",
146                             "value":"frame可无限有级嵌套,frame中放的类型包括frame、text、image、table、chart",
147                             "font-weight":"bold"
148                         }]
149                     }]
150                 }]
151             },{
152                 "type":"title",
153                 "title":"段落配置示例",
154                 "margin-top":"30px"
155             },{
156                 "type":"text",
157                 "text-align":"left",
158                 "margin-top":"20px",
159                 "margin-bottom":"20px",
160                 "items":[{
161                     "type":"image",
162                     "value":"user_orange.png",
163                     "width":"auto",
164                     "height":"auto",
165                     "margin-left":"5px",
166                     "margin-right":"0"
167                 },{
168                     "type":"text",
169                     "value":"同一个段落内容的文本也可显示不",
170                     "text-decoration":"underline",
171                     "font-style":"italic",
172                     "font-weight":"bold",
173                     "font-size":"12px",
174                     "color":"#FF0000",
175                     "margin-left":"0",
176                     "margin-right":"0"
177                 },{
178                     "type":"text",
179                     "value":"同的样式,并且可以显示图片",
180                     "text-decoration":"line-through",
181                     "font-style":"",
182                     "font-weight":"",
183                     "font-size":"20px",
184                     "color":"#0000FF",
185                     "margin-left":"10px",
186                     "margin-right":"10px"
187                 }]
188             },{
189                 "type":"title",
190                 "title":"图片配置示例",
191                 "margin-top":"30px"
192             },{
193                 "type":"image",
194                 "value":"logo.png",
195                 "align":"left",
196                 "margin-top":"10px",
197                 "margin-bottom":"10px",
198                 "width":"",
199                 "height":""
200             },{
201                 "type":"title",
202                 "title":"图表配置示例",
203                 "margin-top":"30px"
204             },{
205                 "id":1,
206                 "type":"chart",
207                 "chart-type":"column",
208                 "y_title":"漏洞数(单位:个)",
209                 "x_title":"安恒报表",
210                 "width":"550",
211                 "height":"300",
212                 "align":"left",
213                 "margin-top":"20px",
214                 "margin-bottom":"20px",
215                 "labels":{
216                     "type":"local",
217                     "value":["一月","二月","三月","四月","五月"]
218                 },
219                 "data":{
220                     "type":"local",
221                     "value":{
222                         "百度":[123,234,111,222,333],
223                         "谷歌":[345,214,567,899,532]
224                     }
225                 }
226             },{
227                 "type":"title",
228                 "title":"表格配置示例",
229                 "margin-top":"30px"
230             },{
231                 "type":"table",
232                 "width":"700px",
233                 "widths":[5,30,30,35],
234                 "row-index":true,
235                 "margin-top":"10px",
236                 "margin-bottom":"0px",
237                 "color-swap":true,
238                 "cols-num":3,
239                 "header":{
240                     "type":"local",
241                     "value":[[{
242                         "text":"表头跨行",
243                         "rows":2
244                     },{
245                         "text":"表头跨列",
246                         "cols":2
247                     }],[{
248                         "text":"表格也可不配置表头"
249                     },{
250                         "text":"表格内容能配置的内容,表头也同样有"
251                     }]]
252                 },
253                 "data":{
254                     "type":"local",
255                     "value":[[{
256                         "text":"可加图标",
257                         "icon":"user_orange.png"
258                     },{
259                         "text":"可设背景",
260                         "background":"#0000FF"
261                     },{
262                         "text":"可设对齐方式",
263                         "text-align":"center"
264                     }],[{
265                         "text":"字号、加粗、下划线",
266                         "font-size":"20px",
267                         "font-weight":"bold",
268                         "text-decoration":"underline"
269                     },{
270                         "text":"颜色、倾斜设置",
271                         "color":"#FF0000",
272                         "font-style":"italic"
273                     },{
274                         "text":"表格内容默认样式"
275                     }],[{
276                         "text":"内容跨行",
277                         "rows":2
278                     },{
279                         "text":"内容跨列",
280                         "cols":2
281                     }],[{
282                         "text":"开启了隔行换色功能"
283                     },{
284                         "text":"开启了显示行号功能"
285                     }]]
286                 }
287             }]
288         }]
289     }]
290 }
291             </textarea>
292             <br/><br/>
293             <input type="submit" value="普通预览" />
294             <input type="button" value="大数据预览" id="bigview"/>
295             <input type="button" value="当前页导出WORD" id="export"/>
296             <input type="button" value="全部导出WORD" id="exportAll"/>
297         </form>
298         <script type="text/javascript" src="js/jquery-1.8.0.min.js"></script>
299         <script type="text/javascript">
300             var formSubmit = function(uri,data){
301                 var form = document.createElement('form');
302                 jQuery.extend(form,{
303                     method:'post',
304                     action:uri
305                 });
306                 
307                 for(var attr in data){
308                     var el = document.createElement('input');
309                     jQuery.extend(el,{
310                         type:'hidden',
311                         name:attr,
312                         value:data[attr]
313                     });
314                     form.appendChild(el);
315                 }
316                 
317                 document.body.appendChild(form);
318                 form.submit();
319             };
320             $(function(){
321                 $("#export").click(function(){
322                     formSubmit('report.export.pt',{
323                         type:3,
324                         pageid:$("#pageid").val(),
325                         content:$("#content").val(),
326                         all:false
327                     });
328                 });
329                 $("#exportAll").click(function(){
330                     formSubmit('report.export.pt',{
331                         type:3,
332                         content:$("#content").val(),
333                         all:true
334                     });
335                 });
336                 $("#bigview").click(function(){
337                     var fm = $("#form");
338                     fm.action = 'report.docPreview.pt';
339                     fm.submit();
340                     /*formSubmit('report.docPreview.pt',{
341                         pageid:$("#pageid").val(),
342                         content:$("#content").val()
343                     });*/
344                 });
345             });
346         </script>
347     </body>
348 </html>

修改处:

View Code
 1 $(function(){
 2     $("#export").click(function(){
 3         formSubmit('report.export.pt',{
 4             type:3,
 5             pageid:$("#pageid").val(),
 6             content:$("#content").val(),
 7             all:false
 8         });
 9     });
10     $("#exportAll").click(function(){
11         formSubmit('report.export.pt',{
12             type:3,
13             content:$("#content").val(),
14             all:true
15         });
16     });
17     $("#bigview").click(function(){
18         var fm = $("#form");
19         fm.action = 'report.docPreview.pt';
20         fm.submit();
21         /*formSubmit('report.docPreview.pt',{
22             pageid:$("#pageid").val(),
23             content:$("#content").val()
24         });*/
25     });
26 });

------------------------------------------------------------------------------------------------

按一下方式修改其内容:


未修改前:

$("#bigview").click(function(){
    formSubmit('report.docPreview.pt',{
        pageid:$("#pageid").val(),
        content:$("#content").val()
    });
}

------------------------------------------------------------------------------------------------

$("#bigview").click(function(){
    var fm = $("#form");
    fm.action = 'report.docPreview.pt';
    fm.submit();
}

------------------------------------------------------------------------------------------------

原文地址:https://www.cnblogs.com/xuejianhui/p/2922368.html