1.composition事件:
- 解决input下汉字输入法重复检测问题
- compositionstart:当浏览器有非直接的文字输入时, compositionstart事件会以同步模式触发.
- compositionend: 当浏览器是直接的文字输入时, compositionend会以同步模式触发.
- 兼容ie 9+.
也就是给input事件触发截流:
var node = $('input');
var flag = false;
node.on('compositionstart', function(){
flag = true;
})
node.on('compositionend', function(){
flag = false;
})
node.on('input', function(){
if(!flag ){
//Todo.....
};
});
2.常用JQ方法:
1.回顶部:
$('body').animate({
scrollTop: '0'
}, 500);
2.多元素绑定生成数据:
$('.div1,.div2,.div3').on('click', '.div4', function() {
fn()
});
3.空处理:
$.trim(keyword) == ''
4.页面间跳转
页面1>>a标签传source>>数据缓存>>页面2>>读url判断>>回退跳回页面1>>读数据清缓存
5.页面尽量多HTML,C3,尽量显示隐藏; 为了避免iphone下失效,浏览器工具菜单栏影响体验,以下是解决办法:
<style type="text/css">
body {
margin: 0 auto;
padding: 0;
width: 100%;
position: fixed;
-webkit-overflow-scrolling: touch;
overflow-scrolling: touch;
overflow: scroll;
}
.box{
width: 100%;
overflow-y: scroll;
float: left;
overflow-x: hidden;
background: gainsboro;
height: 89vh;
}
.pox{
width: 100px;
height: 20vh;
border: 1px solid red;
}
</style>
<body>
<div class="box">
<div class="pox"></div>
<div class="pox"></div>
<div class="pox"></div>
<div class="pox"></div>
<div class="pox"></div>
<div class="pox"></div>
<div class="pox"></div>
</div>
</body>