原生JS选择同胞节点
[ 2015/11/07 19:49 | by 刘新修 ]
XML/HTML代码
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>Document</title>
- <script type="text/javascript">
- window.onload=function(){
- var oli=document.getElementById("box1");
- var obox=oli.parentNode;
- var lis=obox.children;
- for(var i=0;i<lis.length;i++){
- if(lis[i]!=oli){
- lis[i].style.color="red";
- }
- }
- }
- </script>
- </head>
- <body>
- <ul id="box1">
- <li>111</li>
- <li id="antzone">222</li>
- <li>333</li>
- <li>444</li>
- </ul>
- <ul id="box2">
- <li>111</li>
- <li id="antzone">222</li>
- <li>333</li>
- <li>444</li>
- </ul>
- <ul id="box3">
- <li>111</li>
- <li id="antzone">222</li>
- <li>333</li>
- <li>444</li>
- </ul>
- <ul id="box4">
- <li>111</li>
- <li id="antzone">222</li>
- <li>333</li>
- <li>444</li>
- </ul>
- </body>
- </html>
JavaScript代码
- //1.substr
- var src="images/off_1.png";
- //alert(src.substr(7,3));
- //输出:off
- //2.substring
- var src="images/off_1.png";
- var yyy='data:image/png;base64,';
- //alert(src.substring(7,10));
- //alert(yyy.substring(11,14))
- //输出:off
- //3.indexOf
- var src="images/off_1.png";
- //alert(src.indexOf('t'));
- //alert(src.indexOf('i'));
- //alert(src.indexOf('g'));
- //4.split
- var yyy='data:image/png;base64,';
- str=yyy.split(";");
- var args=new Array();
- //alert(str)
- //alert(ss.length[0])
- //alert("2:3:4:5".split(":"))
- //5.Array--split 实例
- /******************************************
- JS分割字符串,Array--split 实例
- *********************************************/
- var argy=new Array(['www'],['jb51'],['net']);
- var strs='data:image/png;base64,';
- var args=new Array(); //定义一数组
- strs=strs.split(";") //数组=split分割后的数据
- var string=strs[0].split("/")
- alert(string[1]); //读取数据,输出png
原JS/封装Ajax图片上传【加载进度条方法】
[ 2015/10/28 17:24 | by 刘新修 ]
JavaScript代码
- /**** 原生JS封装Ajax图片上传【加载进度条方法】 ****/
- ajax({
- //url:'/xdo/marketActivity/task/uploadImage.do',
- url:'/xdo/marketActivity/common/uploadImage.do',
- type:'POST',
- data:{guid:_guid,plat:_plat,file:upload.fileSrc,isMain:upload.isMain,isFinish:upload.finish},
- dataType:'json',
- timeout:9000,
- //xhr:xhrProvider,
- beforeSend:function(){
- var bodyDom=document.getElementsByTagName("body")[0];
- var loading=document.getElementById('loading');
- loading.setAttribute("usable","true");
- loading.style.display="block";
- loading.innerHTML='loading...';
- },
- uploading:function(data){
- console.log(data);
- },
- success:function(data){
- //console.log(data);
- },
- fail:function(data){
- //console.log(data);
- }
- });
- /**** jquery/Ajax图片上传【加载进度条方法】 ****/
- function onprogress(evt){
- // display uploading progress infomation...
- alert(evt.loaded)
- console.log((evt.loaded/evt.total)*100);
- };
- var xhrProvider=function(){
- var xhr=$.ajaxSettings.xhr();
- //var xhr=new XMLHttpRequest();
- //var xhr=ajaxY.xhr;
- //alert(xhr.upload)
- if(onprogress&&xhr.upload){
- xhr.upload.addEventListener('progress', onprogress, false);
- }
- return xhr;
- };
- $.ajax({
- //url:'/xdo/marketActivity/task/uploadImage.do',
- url:'/xdo/marketActivity/common/uploadImage.do',
- type:'POST',
- data:{guid:_guid,plat:_plat,file:upload.fileSrc,isMain:upload.isMain,isFinish:upload.finish},
- dataType:'json',
- timeout:9000,
- xhr:xhrProvider,
- success:function(data){
- //console.log(result);
- },
- error:function(data){
- //console.log(data);
- }
- });
JAVA循环数组输出HTML代码片段并对字符串进行base64编码
[ 2015/10/27 13:04 | by 刘新修 ]
Java代码
- <%@page trimDirectiveWhitespaces="true"%>
- <%@page language="java" pageEncoding="utf-8"%>
- <%@page import="sun.misc.*"%>
- <%@page import="java.io.*"%>
- <%@page import="java.util.*"%>
- <%
- List<String> htmltempList=new ArrayList<String>();
- //String[][] students = {{'小明','1101','23','52819911'},{'夏利','1101','23','52819911'},{'小强','1102','21','52819901'}};
- //创建6行4列二位数组
- String[][] book=new String [6][4];
- book[0]=new String[]{"风清扬","1101","23","52819911"};
- book[1]=new String[]{"许志飞","1101","23","52819911"};
- book[2]=new String[]{"令狐冲","1102","21","52819901"};
- book[3]=new String[]{"任我行","1103","22","52819991"};
- book[4]=new String[]{"任盈盈","1104","24","52819981"};
- book[5]=new String[]{"东方不败","1105","26","52819981"};
- String[][] arr1={{"11","22"},{"aaa","bbb"},{"AAA","BBB"}};
- String[][] arr2=new String[3][2];
- for(int i=0;i<book.length;i++){
- htmltempList.add("<ul>");
- for(int j=0;j<book[i].length;j++){
- //out.println(book[i][j]);
- htmltempList.add("<li>" +book[i][j]+"</li>");
- }
- htmltempList.add("</ul>");
- }
- /*
- int [][]a=new int[8][8];
- for (int i=0;i<8;i++){
- for(int j=0;j<8;j++){
- a[i][j]=i+j;
- out.println(a[i][j]+"---");
- }
- }*/
- //out.println("---");
- %>
- <%
- for (int i=0;i<9;i++){
- //htmltempList.add("<li><span>" + i+"</span></li>");
- }
- /*
- for (int i=0; i<htmltempList.size();i++){
- out.print(htmltempList.get(i));
- }
- out.print(testCol(htmltempList) + "====================");
- */
- %>
- <%
- response.setContentType("text/json");
- response.setCharacterEncoding("utf-8");
- String callback=request.getParameter("Jsoncallback");
- if(callback!=null&&!"".equals(callback)){
- out.print(callback+"({\"dataList\":\"" +testColCon(htmltempList) + "\"})");
- }
- %>
- <%!
- public static int testCol(List<String> testList){
- return testList.size();
- }
- public static String testColCon(List<String> testList){
- String str="";
- String html="<style>*{margin:0;padding:0;}h1{font-size:16px;text-align:center; line-height:45px;}body{color:#333;font-size:14px;font-family:'MicrosoftYahei';background:#B7CACC;}div{border:1px solid #405E7B; border-bottom:0; width:95%; margin:0 auto;background:#fff;content:'';display:table;clear:both}li{line-height:35px;list-style:none;width:25%;text-align:center;border-bottom:1px solid #405E7B;float:left;}</style><h1>最近风云人员名单</h1><div>";
- for (int i=0; i<testList.size();i++){
- str+=testList.get(i);
- }
- html+=str;
- byte[] b=null;
- String s=null;
- try{
- b=html.getBytes("utf-8");
- }catch(UnsupportedEncodingException e){
- e.printStackTrace();
- }
- if (b!=null){
- s=new BASE64Encoder().encode(b);
- s=s.replaceAll("\r\n","");
- s=s.replaceAll("\n","");
- // s = s.replaceAll("","");
- //s="PGxpPjxzcGFuPjA8L3NwYW4+PC9saT48bGk+PHNwYW4+MTwvc3Bhbj48L2xpPjxsaT48c3Bhbj4yPC9zcGFuPjwvbGk+PGxpPjxzcGFuPjM8L3NwYW4+PC9saT48bGk+PHNwYW4+NDwvc3Bhbj48L2xpPjxsaT48c3Bhbj41PC9zcGFuPjwvbGk+PGxpPjxzcGFuPjY8L3NwYW4+PC9saT48bGk+PHNwYW4+Nzwvc3Bhbj48L2xpPjxsaT48c3Bhbj44PC9zcGFuPjwvbGk+";
- }
- return s;
- }
- %>
php循环数组输出HTML代码片段并对字符串进行base64编码
[ 2015/10/23 14:03 | by 刘新修 ]
PHP代码
- <?php
- //公共声明
- header('Content-type: text/json');
- html_entity_decode($string, ENT_QUOTES, 'UTF-8');
- //回调参数设置
- $param="Jsoncallback";
- $callback=$_REQUEST[$param];
- $students=array(
- array("风清扬","1101","23","52819911"),
- array("许志飞","1101","23","52819911"),
- array("令狐冲","1102","21","52819901"),
- array("任我行","1103","22","52819991"),
- array("任盈盈","1104","24","52819981"),
- array("东方不败","1105","26","52819981")
- );
- $tempBegin='<style>*{margin:0;padding:0;}h1{font-size:16px;text-align:center; line-height:45px;}body{color:#333;font-size:14px;font-family:"MicrosoftYahei";background:#B7CACC;}div{border:1px solid #405E7B; border-bottom:0; width:95%; margin:0 auto;background:#fff;content:"";display:table;clear:both}li{line-height:35px;list-style:none;width:25%;text-align:center;border-bottom:1px solid #405E7B;float:left;}</style><h1>最近风云人员名单</h1><div>';
- foreach($students as $v){
- $tempBegin.='
- <ul>
- <li>'.$v[0].'</li>
- <li>'.$v[1].'</li>
- <li>'.$v[2].'</li>
- <li>'.$v[3].'</li>
- </ul>
- ';
- }
- $tempEnd=$tempBegin.'</div>';
- //echo $tempEnd;
- $str1=base64_encode($tempEnd);
- $str2='{"dataList":"'.$str1.'"}';
- $jsonStr=$callback."(".$str2.")";
- //判断请求参数存在就会输出Json数据
- //if(isset($callback)&&!empty($callback)){
- if(isset($callback)){
- echo $jsonStr;
- }
- //判断请求参数不存在就输出错误信息
- if(!isset($callback)){
- header("Content-type: text/html; charset=utf-8");
- $str="<h1>400 Required String parameter '{$param}' is not present</h1><hr /><small>http Request with error params: none callback function</small>";
- echo $str;
- }
- ?>
原生JS对字符串进行base64编码/解码
[ 2015/10/23 13:54 | by 刘新修 ]
JavaScript代码
- /**** 下面是64个基本的编码 ****/
- var base64EncodeChars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
- var base64DecodeChars=new Array(
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
- 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
- -1, 0, 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, -1, -1, -1, -1, -1,
- -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
- 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1);
- /**** 编码的方法 ****/
- function base64encode(str) {
- var out,i,len;
- var c1,c2,c3;
- len=str.length;
- i=0;
- out="";
- while(i<len){
- c1=str.charCodeAt(i++)&0xff;
- if(i==len){
- out+=base64EncodeChars.charAt(c1>>2);
- out+=base64EncodeChars.charAt((c1&0x3)<<4);
- out+="==";
- break;
- }
- c2=str.charCodeAt(i++);
- if(i==len){
- out+=base64EncodeChars.charAt(c1>>2);
- out+=base64EncodeChars.charAt(((c1&0x3)<<4)|((c2&0xF0)>>4));
- out+=base64EncodeChars.charAt((c2&0xF)<<2);
- out+="=";
- break;
- }
- c3=str.charCodeAt(i++);
- out+=base64EncodeChars.charAt(c1>>2);
- out+=base64EncodeChars.charAt(((c1&0x3)<<4)|((c2&0xF0)>>4));
- out+=base64EncodeChars.charAt(((c2&0xF)<<2)|((c3&0xC0)>>6));
- out+=base64EncodeChars.charAt(c3&0x3F);
- }
- return out;
- };
- /**** 解码的方法 ****/
- function base64decode(str){
- var c1,c2,c3,c4;
- var i,len,out;
- len=str.length;
- i=0;
- out="";
- while(i<len){
- do{
- c1=base64DecodeChars[str.charCodeAt(i++)&0xff];
- }while(i<len&&c1==-1);
- if(c1==-1)
- break;
- do{
- c2=base64DecodeChars[str.charCodeAt(i++)&0xff];
- }while(i<len&&c2==-1);
- if(c2==-1)
- break;
- out+=String.fromCharCode((c1<<2)|((c2 & 0x30)>>4));
- do{
- c3=str.charCodeAt(i++)&0xff;
- if(c3==61)
- return out;
- c3=base64DecodeChars[c3];
- }while(i<len&&c3==-1);
- if(c3==-1)
- break;
- out+=String.fromCharCode(((c2&0XF)<<4)|((c3&0x3C)>>2));
- do{
- c4=str.charCodeAt(i++)&0xff;
- if(c4==61)
- return out;
- c4=base64DecodeChars[c4];
- } while(i<len&&c4==-1);
- if(c4==-1)
- break;
- out+=String.fromCharCode(((c3&0x03)<<6)|c4);
- }
- return out;
- };
- function utf16to8(str){
- var out,i,len,c;
- out="";
- len=str.length;
- for(i=0;i<len;i++){
- c=str.charCodeAt(i);
- if((c>=0x0001)&&(c<=0x007F)){
- out+=str.charAt(i);
- }else if(c>0x07FF){
- out+=String.fromCharCode(0xE0|((c>>12)&0x0F));
- out+=String.fromCharCode(0x80|((c>>6)&0x3F));
- out+=String.fromCharCode(0x80|((c>>0)&0x3F));
- }else{
- out+=String.fromCharCode(0xC0|((c>>6)&0x1F));
- out+=String.fromCharCode(0x80|((c>>0)&0x3F));
- }
- }
- return out;
- };
- function utf8to16(str){
- var out,i,len,c;
- var char2,char3;
- out="";
- len=str.length;
- i=0;
- while(i<len){
- c=str.charCodeAt(i++);
- switch(c>>4){
- case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:
- /** 0xxxxxxx **/
- out+=str.charAt(i-1);
- break;
- case 12:case 13:
- /** 110x xxxx 10xx xxxx **/
- char2=str.charCodeAt(i++);
- out+=String.fromCharCode(((c&0x1F)<<6)|(char2&0x3F));
- break;
- case 14:
- /** 1110 xxxx 10xx xxxx 10xx xxxx **/
- char2=str.charCodeAt(i++);
- char3=str.charCodeAt(i++);
- out+=String.fromCharCode(((c&0x0F)<<12)|((char2&0x3F)<<6)|((char3&0x3F)<<0));
- break;
- }
- }
- return out;
- };
- /** 编码 **/
- /** val=base64encode(utf16to8(src)); **/
- /** 解码 **/
- /** val=utf8to16(base64decode(src)); **/
- /** var d="PGgxPjExMTwvaDE+PGRpdiBjbGFzcz0ibmFtZSI+MTEyMjwvZGl2Pg=="; **/
原生JS过滤子级标签【选择器】
[ 2015/10/21 17:18 | by 刘新修 ]
JavaScript代码
- /**
- *
- * @param parent父节点
- * @param ele要选取的元素标签
- * @param num第几个元素
- * @return {*}
- */
- function nth(parent,ele,num){
- var _ele=Array.prototype.slice.call(parent.childNodes),eleArray=[];
- //将父节点的子节点转换成数组_ele;eleArray为只储存元素节点的数组
- for(var i=0,len=_ele.length;i<len;i++){
- if(_ele[i].nodeType==1){
- eleArray.push(_ele[i]);//过滤掉非元素节点
- }
- }
- if(arguments.length===2){
- //如果只传入2个参数,则如果第二个参数是数字,则选取父节点下的第几个元素
- //如果第二个参数是字符串,则选取父节点下的所有参数代表的节点
- if(typeof arguments[1]==="string"){
- _ele=Array.prototype.slice.call(parent.getElementsByTagName(arguments[1]));
- return _ele;
- }else if(typeof arguments[1]==="number"){
- return eleArray[arguments[1]];
- }
- }else{
- //如果参数齐全,则返回第几个某节点,索引从0开始
- _ele=Array.prototype.slice.call(parent.getElementsByTagName(ele));
- return _ele[num];
- }
- };
关于transition和keyframes
[ 2015/10/19 21:08 | by 刘新修 ]
CSS代码
- /***** transition 和 animation ******/
- transition /** 是页面元素的过渡效果,如鼠标划上旋转、变成等 **/
- animation /** 则是动画组,直接指向了动画关键帧,animation-name 对应 @keyframes neme{} **/
- animation-name /** 动画名称 **/
- animation-duration /** 动画的时间 **/
- animation-timing-function /** 设置动画的过渡类型,一般去linear线性过渡 **/
- animation-delay /** 设置延时时间 **/
- animation-iteration-count /** 动画循环次数默认为1 ,infinite为无限循环 **/
- animation-direction /** 动画的方向分为正反,normal为正alternate反 **/
- animation-play-state /** w3c正在考虑是否将该属性移除,你建议使用! **/
- animation-fill-mode /** 默认值为:none,设置forwards时停留在最后一帧; **/
- /***** animation缩写:*****/
- /*******************************************************************/
- animation:name 1s linear 5s forwards; /*** 定义在随着一帧 ***/
- animation:name 1s linear 5s infinite; /*** 一直循环动画 ***/
- animation:mymove 1s linear 5s infinite forwards; /*** 错误的 ***/
- /*** infinite 和 forwards 不可同时定义 ***/
- /**********************************************************************/
- @-webkit-keyframes name{
- from { }
- to { }
- }
- @-o-keyframes name{
- from { }
- to { }
- }
- @-moz-keyframes name{
- from { }
- to { }
- }
- @keyframes name{
- from { }
- to { }
- }
timing-function 作用于每两个关键帧之间,而不是整个动画
C#代码
- ls -lart
- mv xfile xfile.20151012
- svn co svn://192.168.3.121/xfile
NGINX 413 解决方法
[ 2015/10/14 17:14 | by 刘新修 ]
413 Request Entity Too Large
NGINX报出413错误是因请求body体上传文件过大导致,修改nginx.conf,在http{} 内部加入以下即可:
client_max_body_size 64M; #body体力最大上传大小,具体多少M根据实际情况填写