第一页 1 最后页 [ 显示模式: 摘要 | 列表 ]

1. 调用广告平台要对超链接字符串局部进行替换,如下:

 

2. 对广告HTTP接口需要改造成支持跨越,在回调方法内部插入JSON数据,回调名:Jsoncallback 如下:

Java代码
  1. @RequestParam(value = "Jsoncallback", required = true) String jsonCallBack,  
  2. JSONObject jsonObject = new JSONObject();  
  3. jsonObject.put("userList", userList);  
  4. String strResult = jsonCallBack+"("+jsonObject.toString()+")";  
  5. return strResult;  

 

网页可见区域宽:document.body.clientWidth

网页可见区域高:document.body.clientHeight
网页可见区域宽:document.body.offsetWidth (包括边线的宽)
网页可见区域高:document.body.offsetHeight (包括边线的宽)
网页正文全文宽:document.body.scrollWidth
网页正文全文高:document.body.scrollHeight
网页被卷去的高:document.body.scrollTop
网页被卷去的左:document.body.scrollLeft
网页正文部分上:window.screenTop
网页正文部分左:window.screenLeft
屏幕分辨率的高:window.screen.height
屏幕分辨率的宽:window.screen.width
屏幕可用工作区高度:window.screen.availHeight
屏幕可用工作区宽度:window.screen.availWidth
 
 
HTML精确定位:scrollLeft,scrollWidth,clientWidth,offsetWidth
scrollHeight: 获取对象的滚动高度。
scrollLeft:设置或获取位于对象左边界和窗口中目前可见内容的最左端之间的距离
scrollTop:设置或获取位于对象最顶端和窗口中可见内容的最顶端之间的距离
scrollWidth:获取对象的滚动宽度
offsetHeight:获取对象相对于版面或由父坐标 offsetParent 属性指定的父坐标的高度
offsetLeft:获取对象相对于版面或由 offsetParent 属性指定的父坐标的计算左侧位置
offsetTop:获取对象相对于版面或由 offsetTop 属性指定的父坐标的计算顶端位置
event.clientX 相对文档的水平座标
event.clientY 相对文档的垂直座标
event.offsetX 相对容器的水平坐标
event.offsetY 相对容器的垂直坐标
document.documentElement.scrollTop 垂直方向滚动的值
event.clientX+document.documentElement.scrollTop 相对文档的水平座标+垂直方向滚动的量
 
IE,FireFox 差异如下:
 
IE6.0、FF1.06+:
clientWidth = width + padding
clientHeight = height + padding
offsetWidth = width + padding + border
offsetHeight = height + padding + border
 
IE5.0/5.5:
clientWidth = width - border
clientHeight = height - border
offsetWidth = width
offsetHeight = height
 
(需要提一下:CSS中的margin属性,与clientWidth、offsetWidth、clientHeight、offsetHeight均无关)
网页可见区域宽: document.body.clientWidth
网页可见区域高: document.body.clientHeight
网页可见区域宽: document.body.offsetWidth (包括边线的宽)
网页可见区域高: document.body.offsetHeight (包括边线的高)
网页正文全文宽: document.body.scrollWidth
网页正文全文高: document.body.scrollHeight
网页被卷去的高: document.body.scrollTop
网页被卷去的左: document.body.scrollLeft
网页正文部分上: window.screenTop
网页正文部分左: window.screenLeft
屏幕分辨率的高: window.screen.height
屏幕分辨率的宽: window.screen.width
屏幕可用工作区高度: window.screen.availHeight
屏幕可用工作区宽度: window.screen.availWidth
-------------------
技术要点
本节代码主要使用了Document对象关于窗口的一些属性,这些属性的主要功能和用法如下。
要得到窗口的尺寸,对于不同的浏览器,需要使用不同的属性和方法:若要检测窗口的真实尺寸,在Netscape下需要使用Window的属性;在IE下需要 深入Document内部对body进行检测;在DOM环境下,若要得到窗口的尺寸,需要注意根元素的尺寸,而不是元素。
Window对象的innerWidth属性包含当前窗口的内部宽度。Window对象的innerHeight属性包含当前窗口的内部高度。
Document对象的body属性对应HTML文档的标签。Document对象的documentElement属性则表示HTML文档的根节点。
document.body.clientHeight表示HTML文档所在窗口的当前高度。document.body. clientWidth表示HTML文档所在窗口的当前宽度。
XML/HTML代码
  1. 实现代码  
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  
  3. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  4. <html xmlns="http://www.w3.org/1999/xhtml">  
  5. <head>  
  6. <title>请调整浏览器窗口</title>  
  7. <meta http-equiv="content-type" content="text/html; charset=gb2312">  
  8. </head>  
  9. <body>  
  10. <h2 align="center">请调整浏览器窗口大小</h2><hr>  
  11. <form action="#" method="get" name="form1" id="form1">  
  12. <!--显示浏览器窗口的实际尺寸-->  
  13. 浏览器窗口 的 实际高度: <input type="text" name="availHeight" size="4"><br>  
  14. 浏览器窗口 的 实际宽度: <input type="text" name="availWidth" size="4"><br>  
  15. </form>  
  16. <script type="text/javascript">  
  17. <!--  
  18. var winWidth = 0;  
  19. var winHeight = 0;  
  20. function findDimensions() //函数:获取尺寸  
  21. {  
  22. //获取窗口宽度  
  23. if (window.innerWidth)  
  24. winWidth = window.innerWidth;  
  25. else if ((document.body) && (document.body.clientWidth))  
  26. winWidth = document.body.clientWidth;  
  27. //获取窗口高度  
  28. if (window.innerHeight)  
  29. winHeight = window.innerHeight;  
  30. else if ((document.body) && (document.body.clientHeight))  
  31. winHeight = document.body.clientHeight;  
  32. //通过深入Document内部对body进行检测,获取窗口大小  
  33. if (document.documentElement  && document.documentElement.clientHeight && document.documentElement.clientWidth)  
  34. {  
  35. winHeight = document.documentElement.clientHeight;  
  36. winWidth = document.documentElement.clientWidth;  
  37. }  
  38. //结果输出至两个文本框  
  39. document.form1.availHeight.value= winHeight;  
  40. document.form1.availWidth.value= winWidth;  
  41. }  
  42. findDimensions();  
  43. //调用函数,获取数值  
  44. window.onresize=findDimensions;  
  45. //-->  
  46. </script>  
  47. </body>  
  48. </html>  
源程序解读
 
(1)程序首先建立一个表单,包含两个文本框,用于显示窗口当前的宽度和高度,并且,其数值会随窗口大小的改变而变化。
(2)在随后的JavaScript代码中,首先定义了两个变量winWidth和winHeight,用于保存窗口的高度值和宽度值。
(3)然后,在函数findDimensions ( )中,使用window.innerHeight和window.innerWidth得到窗口的高度和宽度,并将二者保存在前述两个变量中。
(4)再通过深入Document内部对body进行检测,获取窗口大小,并存储在前述两个变量中。
(5)在函数的最后,通过按名称访问表单元素,结果输出至两个文本框。
(6)在JavaScript代码的最后,通过调用findDimensions ( )函数,完成整个操作。
 

jQuery 获取屏幕高度、宽度

 

JavaScript代码
  1. ajax({  
  2.     url:"http://192.168.66.90:8080/php/test5.php",  
  3.     type:"POST",  
  4.     data:{GUID:"288350897",subFlag:"1"},  
  5.     dataType:"jsonp",  
  6.     callback:"Jsoncallback",  
  7.     success:function(data){  
  8.         if(data.sex==0){  
  9.             var userSex="帅哥";  
  10.         }  
  11.         if(data.sex==1){  
  12.             var userSex="美女";  
  13.         }  
  14.         if(data.switch==0){  
  15.             $(".Mbox .mailInfo .text_").html('<span style="color:#fbff83">'+data.mailInfo+'</span>封'+userSex+'来信');  
  16.             $(".Mbox").addClass("ty");  
  17.             mbox.addEventListener("webkitAnimationEnd",function(){ //动画结束时事件  
  18.             var timer=setInterval(function(){  
  19.             if(mbox.offsetTop==-60){  
  20.                 mbox.className='Mbox tyy';  
  21.                 clearInterval(timer)  
  22.             }  
  23.             },1000)  
  24.             },false);  
  25.         }  
  26.         //alert(data.switch)  
  27.   
  28. },  
  29.     fail:function(status){  
  30.     // 此处放失败后执行的代码  
  31.     }  
  32. });  
  33.   
  34. /***********************************
  35. 公共ajax方法支持跨越请求
  36. ************************************/  
  37. function ajax(options) {  
  38. options = options||{};  
  39. if (!options.url||!options.callback){  
  40. throw new Error("参数不合法");  
  41. }  
  42.   
  43. //创建 script 标签并加入到页面中  
  44. var callbackName=('jsonp_'+Math.random()).replace(".","");  
  45. var oHead=document.getElementsByTagName('head')[0];  
  46. options.data[options.callback]=callbackName;  
  47. var params=formatParams(options.data);  
  48. var oS=document.createElement('script');  
  49. oHead.appendChild(oS);  
  50.   
  51. //创建jsonp回调函数  
  52. window[callbackName]=function(json){  
  53. oHead.removeChild(oS);  
  54. clearTimeout(oS.timer);  
  55. window[callbackName]=null;  
  56. options.success&&options.success(json);  
  57. };  
  58.   
  59. //发送请求  
  60. oS.src=options.url+'?'+params;  
  61.   
  62. //超时处理  
  63. if(options.time){  
  64. oS.timer=setTimeout(function(){  
  65. window[callbackName]=null;  
  66. oHead.removeChild(oS);  
  67. options.fail&&options.fail({message:"超时"});  
  68. },time);  
  69. }  
  70. };  
  71.   
  72. //格式化参数  
  73. function formatParams(data){  
  74. var arr=[];  
  75. for(var name in data){  
  76. arr.push(encodeURIComponent(name)+"="+encodeURIComponent(data[name]));  
  77. }  
  78. return arr.join('&');  
  79. }  

 

Tags: ,

 

XML/HTML代码
  1. <!doctype html>  
  2. <html lang="en">  
  3. <head>  
  4.     <meta charset="UTF-8">  
  5.     <title>jQuery制作从左到右从新排列内容动画特效</title>  
  6.     <style>  
  7.     body{ height: 3000px; padding: 0; margin: 0; }  
  8.     div{ background: #000; margin: 20px 0; width: 100px; height: 30px; color: #fff; line-height: 30px; text-align: center; }  
  9.     </style>  
  10. </head>  
  11.  <script src="js/jquery.min.js"></script>  
  12.  <body>  
  13.     <div class="op1">111</div>  
  14.     <div class="op2">222</div>  
  15.     <div class="op3">333</div>  
  16.     <div class="op4">444</div>  
  17.     <div class="op5">555</div>  
  18.     <div class="op6">666</div>  
  19.     <div class="op7">777</div>  
  20.     <input type="button" value="stop!!!" />  
  21.     <script>  
  22.     var _width = ($(document).width() - $('div').width()) + "px";  
  23.   
  24.     var animateList=[   
  25.           function(){ $('.op1').delay(500).animate({marginLeft:_width},500,queueList);  },   
  26.           function(){ $('.op2').delay(300).animate({marginLeft:_width},500,queueList);  },   
  27.           function(){ $('.op3').delay(300).animate({marginLeft:_width},500,queueList);  },   
  28.           function(){ $('.op4').delay(700).animate({marginLeft:_width},500,queueList);  },   
  29.           function(){ $('.op5').delay(300).animate({marginLeft:_width},500,queueList);  },   
  30.           function(){ $('.op6').delay(200).animate({marginLeft:_width},500,queueList);  },   
  31.           function(){ $('.op7').delay(300).animate({marginLeft:_width},500,function(){ alert('动画队列结束'); } );}  
  32.     ];   
  33.       
  34.     $(document).queue('_queueList',animateList);   
  35.     var queueList=function(){   
  36.         $(document).dequeue('_queueList');   
  37.     };   
  38.     queueList();  
  39.   
  40.     $(':button').click(function(){  
  41.         $(document).clearQueue('_queueList');  
  42.     });  
  43.   
  44.     </script>  
  45.   
  46. </body>  
  47. </html>  

 

Linux复制本地文件到远程

[不指定 2015/06/17 10:06 | by 刘新修 ]

 scp -r /www/next.youyuan.com2 root@192.168.3.162:/www/

JSON 常用类型处理

[不指定 2015/06/16 11:54 | by 刘新修 ]

 

JavaScript代码
  1. var str='{"weatherinfo": [{"city": "北京","city_en": "beijing", "cityid": "101130101","date": "","date_y": "2014年1月23日", "wind6": "微风"}]}';  
  2. var obj=JSON.parse(str);  
  3. var yy=JSON.stringify(obj);  
  4. alert(yy)  

 

JS设置数组随机取值,支持多个不重复【实例】

XML/HTML代码
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2. <html xmlns="http://www.w3.org/1999/xhtml">  
  3. <head>  
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
  5. <title>无标题文档</title>  
  6. </head>  
  7. <body Arrdata="1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33">  
  8. </body>  
  9. <script type="text/javascript" src="http://code.liuxinxiu.com/lib/zepto/zepto-1.1.6.js"></script>  
  10. <script language="javascript">  
  11. //从一个给定的数组arr中,随机返回num个不重复项  
  12. function getArrayItems(arr, num) {  
  13.     //新建一个数组,将传入的数组复制过来,用于运算,而不要直接操作传入的数组;  
  14.     var temp_array = new Array();  
  15.     for (var index in arr) {  
  16.         temp_array.push(arr[index]);  
  17.     }  
  18.     //取出的数值项,保存在此数组  
  19.     var return_array = new Array();  
  20.     for (var i = 0; i<num; i++) {  
  21.         //判断如果数组还有可以取出的元素,以防下标越界  
  22.         if (temp_array.length>0) {  
  23.             //在数组中产生一个随机索引  
  24.             var arrIndex = Math.floor(Math.random()*temp_array.length);  
  25.             //将此随机索引的对应的数组元素值复制出来  
  26.             return_array[i] = temp_array[arrIndex];  
  27.             //然后删掉此索引的数组元素,这时候temp_array变为新的数组  
  28.             temp_array.splice(arrIndex, 1);  
  29.         } else {  
  30.             //数组中数据项取完后,退出循环,比如数组本来只有10项,但要求取出20项.  
  31.             break;  
  32.         }  
  33.     }  
  34.     return return_array;  
  35. }  
  36.   
  37. //测试  
  38. var ArrData=$("body").attr("Arrdata");  
  39. //var ArrList=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33];  
  40. var data=ArrData.split(",");//已经是数组,直接可以用str[0]去取了  
  41. //alert(str[1])  
  42. //alert(getArrayItems(arr,2));  
  43. var html=getArrayItems(data,2);  
  44. for(var i=0;i<html.length;i++){  
  45.     alert(html[i])  
  46. }  
  47. document.write(html)  
  48. </script>  
  49. </html>  

 

 JS遍历2层DOM装入数组转JSON【实例】

XML/HTML代码
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2. <html xmlns="http://www.w3.org/1999/xhtml">  
  3. <head>  
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
  5. <title>无标题文档</title>  
  6. <style>  
  7. *{ margin:0; padding:0;}  
  8. body{ color:#333; font-family:'Microsoft Yahei'; font-size:16px;}  
  9. ul,li{ list-style:none; line-height:30px;}  
  10. .conbox{ padding:10px;}  
  11. .conbox .selected{ color:#CC0033}  
  12. .conbox .lis span{ padding:0 5px;}  
  13. </style>  
  14. </head>  
  15. <body arrData="111,222,333,444,555,666">  
  16. <div class="conbox">  
  17.     <ul class="lisbox">  
  18.         <li data-qId="11" n="aaa" class="lis selected"><span class="on">111c</span><span class="on">222c</span><span class="on">333c</span></li>  
  19.         <li data-qId="22" n="bbb" class="lis">bbb</li>  
  20.         <li data-qId="33" n="ccc" class="lis selected"><span class="on">111a</span><span class="on">222a</span><span class="on">333a</span></li>  
  21.         <li data-qId="44" n="ddd" class="lis">ddd</li>  
  22.         <li data-qId="55" n="eee" class="lis selected"><span class="on">111b</span><span class="on">222b</span><span class="on">333b</span></li>  
  23.         <li data-qId="66" n="fff" class="lis">fff</li>  
  24.     </ul>  
  25. </div>  
  26. <div id="submitBtn" style=" width:100%; height:50px; line-height:50px; text-align:center; color:#fff; background:#CC0000">点击事件</div>  
  27. </body>  
  28. <script type="text/javascript" src="http://code.liuxinxiu.com/lib/zepto/zepto-1.1.6.js"></script>  
  29. <script type="text/javascript">  
  30. $("#submitBtn").on("click",function(){  
  31.     /*********  声明变量获取节点 ***************/  
  32.     var qList=$(".lisbox li.selected"),qLen=qList.length,arr=[];  
  33.     /*********  循环第一层问题 ***********/  
  34.     for(var i=0;i<qLen;i++){  
  35.         /**** var $anList=$qList.eq(i).find("[name=an" + i + "]:checked"),subArr=[]; ****/  
  36.         var anList=qList.eq(i).find(".on"),subArr=[];  
  37.         var qid=qList.eq(i).attr("data-qId");  
  38.         /*****  循环第二层答案  **********/  
  39.         for(var key=0;key<anList.length;key++){  
  40.             subArr.push(anList.eq(key).text());  
  41.         }  
  42.         /*****  添加到整体数组 ************/  
  43.         arr.push({Question:qid,Answer:subArr});  
  44.     }  
  45.     /***** 转化成JSON结构字符串 *******/  
  46.     var subArrst=JSON.stringify(subArr);  
  47.     var jsondata=JSON.stringify(arr);  
  48.     /***** 使用replace替换"号为空、可全部 ******/  
  49.     var _subArrst=subArrst.replace(/"/g,"");  
  50.     var _datalist=jsondata.replace(/"/g,"");  
  51.     var _dataJson={guId:111222,eventId:11,plat:5,datalist:subArrst};  
  52.     alert(_datalist)  
  53. });  
  54. </script>  
  55. </html>  

 

 两种方式

 
<c:set var="s1" value="This is One" scope="request" />
out.print(request.getAttribute("s1") ;
 
<c:set var="s2" value="This is Two"/>
out.print(pageContext.getAttribute("s2"));
 
----------------------------------------------------
JSTL 变量由 JSP 读取
 
<c:set var="JspValue1" value="Java Language One" scope="request" /> 
<c:set var="JspValue2" value="Java Language Two"/>
<%
String JspValue3 = request.getAttribute("JspValue1").toString();
String JspValue4 = pageContext.getAttribute("JspValue2").toString();
          
out.print(JspValue3);
out.print(JspValue4);
%>
 
----------------------------------------------------
 
JSP 变量由 JSTL 读取
String strContextPath = request.getContextPath();
 pageContext.setAttribute("ContextPath", strContextPath);
..
<c:out value="${ContextPath}"></out>
第一页 1 最后页 [ 显示模式: 摘要 | 列表 ]