Skip to content

Instantly share code, notes, and snippets.

@Visionchen
Last active November 28, 2019 11:07
Show Gist options
  • Select an option

  • Save Visionchen/32678aa85cb11d00aa034126a6988e03 to your computer and use it in GitHub Desktop.

Select an option

Save Visionchen/32678aa85cb11d00aa034126a6988e03 to your computer and use it in GitHub Desktop.
常见
### 苹果键盘顶上内容不下来/安卓input被遮住(input框)
```javascript
内容1屏
if(isAndroid){
var winHeight = $(window).height(); //获取当前页面高度
$(window).resize(function() {
var thisHeight = $(this).height();
if (winHeight - thisHeight > 50) {
//当软键盘弹出,在这里面操作
$('.page-content').css({'height': winHeight + 'px','minHeight':'auto','position':'absolute','bottom':'0'});
} else {
//当软键盘收起,在此处操作
$('.page-content').css({'height': '100vh','minHeight':'100vh','position':'relative',});
}
});
}else if(isiOS){
$('#mobile').focus(function () {
window.scrollTo(0,$(window).height());
});
$('#code').focus(function () {
window.scrollTo(0,$(window).height());
});
$('#mobile').blur(function () {
document.querySelector('#code').scrollIntoView();
if (document.getElementById('code') != document.activeElement) {
window.scrollTo(0,0);
}
});
$('#code').blur(function () {
document.querySelector('#code').scrollIntoView();
if (document.getElementById('mobile') != document.activeElement) {
window.scrollTo(0,0);
}
});
}
2
var u = navigator.userAgent, app = navigator.appVersion;
var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //根据输出结果true或者false来判断ios终端
//!!双叹号一般用来将后面的表达式转换为布尔型的数据(boolean)
if(isiOS){
$('.textArea').focus(function () {
window.scrollTo(0,$(window).height());
});
$('.textArea').blur(function () {
document.querySelector('.textArea').scrollIntoView();
window.scrollTo(0,0);
});
}
```
### 数据中是否存在指定值,存在就删除
```javascript
var str = ["a", "b", "c"];
var index = str.indexOf("a");
if(index>-1){//大于0 代表存在,
str.splice(index,1);//存在就删除
}
console.log(str);// ["b", "c"]
```
### 数组对象中是否存在指定值(方法一),存在即删除
```javascript
var searchinfo =[
{ key: '999', name: 'zhangsan'},
{ key: '111', name: 'lisi'},
{ key: '222', name: 'wanger'},
{ key: '333', name: 'apple'},
{ key: '444', name: 'orange'},
]
for (var i = 0; i < searchinfo.length; i++) {
            if ((searchinfo[i].key).indexOf("999") > -1) {//判断key为999的对象是否存在,
                index = i;
                searchinfo.splice(index, 1);//存在即删除
            }
        }
console.log(searchinfo);
```
### 数组对象中是否存在指定值(方法二)
```javascript
var searchinfo =[
{ key: '999', name: 'zhangsan'},
{ key: '111', name: 'lisi'},
{ key: '222', name: 'wanger'},
{ key: '333', name: 'apple'},
{ key: '444', name: 'orange'},
]
var str1 = searchinfo.some(item => item.key =="999");
console.log(str);//true 存在
var str2 = searchinfo.some(item => item.key =="121");
console.log(str);//false 不存在
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment