通过ajax获取json时要过滤的特殊字符
\ufeff
\u2028
\u2029
\xa0(这个也可以替换为空格)
JS仿PHP shuffle、range、in_array
Array.prototype.shuffle = function() { for(var j, x, i = this.length; i; j = parseInt(Math.random() * i), x = this[--i], this[i] = this[j], this[j] = x); return this; }; function range(startNum, endNum, stepNum){ for(var arr=[], i=startNum; i<=endNum; arr.push(i), i+=(stepNum ? stepNum : 1)); return arr; } function in_array(obj, arr){ for(var i in arr){ if(arr[i]===obj)return true; } return false; }
在JavaScript 1.6中in_array有对应的原生函数arr.indexOf(search)
注:IE浏览器暂不支持 JavaScript 1.6
JS运算符优先级
下表按从最高到最低的优先级列出JavaScript运算符。具有相同优先级的运算符按从左至右的顺序求值。
运算符 | 描述 |
. [] () | 字段访问、数组下标、函数调用以及表达式分组 |
++ -- - ~ ! delete new typeof void | 一元运算符、返回数据类型、对象创建、未定义值 |
* / % | 乘法、除法、取模 |
+ - + | 加法、减法、字符串连接 |
<< >> >>> | 移位 |
< <= > >= instanceof | 小于、小于等于、大于、大于等于、instanceof |
== != === !== | 等于、不等于、严格相等、非严格相等 |
& | 按位与 |
^ | 按位异或 |
| | 按位或 |
&& | 逻辑与 |
|| | 逻辑或 |
?: | 条件 |
= oP= | 赋值、运算赋值 |
, | 多重求值 |
jquery background animate
$("div").animate({
backgroundPositionX: "-120px",
backgroundPositionY: "0px"
})
backgroundPositionX: "-120px",
backgroundPositionY: "0px"
})
jquery操作select
判断select的选中情况
$('select').find('option:selected').index()
$('select').find('option:selected').prop('value')
$('select').find('option:first').text()
设置值是abc的option为选中状态
$('select').val('abc');
$("select option[value='abc']").prop('selected', 'selected');
删除元素
$('select > option').remove()
$('select > option:gt(0)').remove()
$('select').empty()
$('select').find('option:selected').index()
$('select').find('option:selected').prop('value')
$('select').find('option:first').text()
设置值是abc的option为选中状态
$('select').val('abc');
$("select option[value='abc']").prop('selected', 'selected');
删除元素
$('select > option').remove()
$('select > option:gt(0)').remove()
$('select').empty()
CSS3切换效果
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
html, body, #wrapper{height:100%;width:100%;overflow:hidden;margin:0;padding:0;background:#eee}
#wrapper #content{width:100%;height:100%;background:#fff}
#wrapper #content{
-moz-transition:all 1.2s cubic-bezier(0.23, 1, 0.32, 1);
-webkit-transition: all 1.2s cubic-bezier(0.23, 1, 0.32, 1);
transition:all 1.2s cubic-bezier(0.23, 1, 0.32, 1);
}
#wrapper.on #content{
-webkit-transform:scale(.7,.7);
-moz-transform:scale(.7,.7);
transform:scale(.7,.7);backgound:#
}
#open{
position:absolute; top:0; left:0; visibility:hidden;
-webkit-transform:translateY(100%) scale(.5,.5);
-moz-transform:translateY(100%) scale(.5,.5);
-ms-transform:translateY(100%) scale(.5,.5);
transform:translateY(100%) scale(.5,.5);
-moz-transition:all 1.6s cubic-bezier(0.23, 1, 0.32, 1);
-webkit-transition: all 1.6s cubic-bezier(0.23, 1, 0.32, 1);
transition:all 1.6s cubic-bezier(0.23, 1, 0.32, 1);
background:#fff;width:100%;height:100%;z-index:1100
}
#open.on{ visibility:visible;
-webkit-transform:translateY(0%) scale(.5,.5);
-moz-transform:translateY(0%) scale(.5,.5);
-ms-transform:translateY(0%) scale(.5,.5);
transform:translateY(0%) scale(.5,.5);
-moz-transition:all .5s cubic-bezier(0.23, 1, 0.32, 1);
-webkit-transition: all .5s cubic-bezier(0.23, 1, 0.32, 1);
transition:all .5s cubic-bezier(0.23, 1, 0.32, 1);
}
#open.s{
-moz-transition:all 1.2s cubic-bezier(0.23, 1, 0.32, 1);
-webkit-transition: all 1.2s cubic-bezier(0.23, 1, 0.32, 1);
transition:all 1.2s cubic-bezier(0.23, 1, 0.32, 1);
-webkit-transform:translateY(0%) scale(1,1);
-moz-transform:translateY(0%) scale(1,1);
-ms-transform:translateY(0%) scale(1,1);
transform:translateY(0%) scale(1,1);
}
#open a.close{position:absolute;top:10px;right:10px;border:solid 1px #eee;width:20px;height:20px;text-align:center;line-height:20px}
#mask{ width:100%; height:100%; position:fixed; top:0; left:0; background:rgba(0,0,0,.4); visibility:hidden; opacity:0; }
#mask.on{visibility:visible;opacity:1;}
</style>
<script src="http://libs.baidu.com/jquery/1.10.0/jquery.min.js"></script>
</head>
<body>
<div id="wrapper">
<div id="content"><a href="http://www.baidu.com/">新闻标题</a></div>
</div>
<div id="open">新闻内容<a href="#" class="close">X</a></div>
<div id="mask"></div>
<script>
$('#content a').click(function(){
$('#open,#wrapper,#mask').addClass('on');
setTimeout(function(){$('#open').addClass('s');},500);
return false;
})
$('#open a.close').click(function(){
$('#open').removeClass('s');
setTimeout(function(){$('#open,#wrapper,#mask').removeClass('on')},500);
return false;
})
</script>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<style>
html, body, #wrapper{height:100%;width:100%;overflow:hidden;margin:0;padding:0;background:#eee}
#wrapper #content{width:100%;height:100%;background:#fff}
#wrapper #content{
-moz-transition:all 1.2s cubic-bezier(0.23, 1, 0.32, 1);
-webkit-transition: all 1.2s cubic-bezier(0.23, 1, 0.32, 1);
transition:all 1.2s cubic-bezier(0.23, 1, 0.32, 1);
}
#wrapper.on #content{
-webkit-transform:scale(.7,.7);
-moz-transform:scale(.7,.7);
transform:scale(.7,.7);backgound:#
}
#open{
position:absolute; top:0; left:0; visibility:hidden;
-webkit-transform:translateY(100%) scale(.5,.5);
-moz-transform:translateY(100%) scale(.5,.5);
-ms-transform:translateY(100%) scale(.5,.5);
transform:translateY(100%) scale(.5,.5);
-moz-transition:all 1.6s cubic-bezier(0.23, 1, 0.32, 1);
-webkit-transition: all 1.6s cubic-bezier(0.23, 1, 0.32, 1);
transition:all 1.6s cubic-bezier(0.23, 1, 0.32, 1);
background:#fff;width:100%;height:100%;z-index:1100
}
#open.on{ visibility:visible;
-webkit-transform:translateY(0%) scale(.5,.5);
-moz-transform:translateY(0%) scale(.5,.5);
-ms-transform:translateY(0%) scale(.5,.5);
transform:translateY(0%) scale(.5,.5);
-moz-transition:all .5s cubic-bezier(0.23, 1, 0.32, 1);
-webkit-transition: all .5s cubic-bezier(0.23, 1, 0.32, 1);
transition:all .5s cubic-bezier(0.23, 1, 0.32, 1);
}
#open.s{
-moz-transition:all 1.2s cubic-bezier(0.23, 1, 0.32, 1);
-webkit-transition: all 1.2s cubic-bezier(0.23, 1, 0.32, 1);
transition:all 1.2s cubic-bezier(0.23, 1, 0.32, 1);
-webkit-transform:translateY(0%) scale(1,1);
-moz-transform:translateY(0%) scale(1,1);
-ms-transform:translateY(0%) scale(1,1);
transform:translateY(0%) scale(1,1);
}
#open a.close{position:absolute;top:10px;right:10px;border:solid 1px #eee;width:20px;height:20px;text-align:center;line-height:20px}
#mask{ width:100%; height:100%; position:fixed; top:0; left:0; background:rgba(0,0,0,.4); visibility:hidden; opacity:0; }
#mask.on{visibility:visible;opacity:1;}
</style>
<script src="http://libs.baidu.com/jquery/1.10.0/jquery.min.js"></script>
</head>
<body>
<div id="wrapper">
<div id="content"><a href="http://www.baidu.com/">新闻标题</a></div>
</div>
<div id="open">新闻内容<a href="#" class="close">X</a></div>
<div id="mask"></div>
<script>
$('#content a').click(function(){
$('#open,#wrapper,#mask').addClass('on');
setTimeout(function(){$('#open').addClass('s');},500);
return false;
})
$('#open a.close').click(function(){
$('#open').removeClass('s');
setTimeout(function(){$('#open,#wrapper,#mask').removeClass('on')},500);
return false;
})
</script>
</body>
</html>
jquery.pjax.js
原理 html5 api:
history.state
history.pushState
history.replaceState
history.state
history.pushState
history.replaceState
CSS控制打印时内容
在CSS代码中加入以下内容即可:
@media print{ /*以下为打印时载入的CSS代码*/ .banner, .sidebar{display:none;} #wrapper, .main{clear:both;width:100% !important;height:auto !important;} }