msforest / notebook

好记性不如烂笔头,记录知识的点点滴滴。
https://github.com/msforest/notebook/wiki
0 stars 0 forks source link

问题汇总 #14

Open msforest opened 7 years ago

msforest commented 7 years ago
msforest commented 7 years ago

移动端问题

1. 阻止移动设备自动识别页面上的电话号码、email地址

移动设备会自动识别数字开启相应的功能,通过下面代码阻止设备自动识别

<meta name="format-detection" content="telephone=no" />
<meta name="format-detection" content="email=no" />
<meta name="format-detection" content="address=no" />
<meta name="format-detection" content="date=no" />

如果需要开启相应的功能,在link上加相应的代码如<a href="tel:8602188888888">+86 021 88888888</a>

2. IOS10.3发布后对CompositionEvent 状态的更改

复合事件是dom3级事件中新增的一类事件,用于处理IME(Input Method Editor,输入法编辑器)的输入序列,有compositionstart/compositionupdate/compositionend三种,对于输入键盘上能找到的字符一般使用change事件,而对于像中文、拉丁文等物理键盘上找不到的字符,使用复合事件进行处理;而在chrome53之后和ios10.3以后把change事件复合事件顺序做了调整,因此变更之后需要对事件进行手动处理,在compositionend之后手动调用一次change事件。

    // Opera 8.0+
    const isOpera = (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;
    // Firefox 1.0+
    const isFirefox = typeof InstallTrigger !== 'undefined';
    // Safari 3.0+ "[object HTMLElementConstructor]"
    const isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0 || (function (p) { return p.toString() === "[object SafariRemoteNotification]"; })(!window['safari'] ||     safari.pushNotification);
    // 是否是IOS系统
    const isIOS = navigator.userAgent.indexOf('iPhone') >= 0 || navigator.userAgent.indexOf('iPad');
    // 获取IOS系统版本
    const IOSVer = navigator.userAgent.match(/\d[\d]*_\d[_\d]*/i) && parseFloat(navigator.userAgent.match(/\d[\d]*_\d[_\d]*/i)[0].split('_').join('.'));
    // Internet Explorer 6-11
    const isIE = /*@cc_on!@*/false || !!document.documentMode;
    // Edge 20+
    const isEdge = !isIE && !!window.StyleMedia;
    // Chrome 1+
    const isChrome = !!window.chrome;
    // Blink engine detection
    const isBlink = (isChrome || isOpera) && !!window.CSS;

   let isComposition = false;
   element.addEventListener('compositionstart', function(e){
     isComposition = true;
  }, false};
   element.addEventListener('compositionend', function(e){
      isComposition = false;
    if(isChrome || (isIOS && IOSVer >= 10.3) ){ // 判断浏览器是否是Chrome 或者 是否是IOS系统以及 IOS版本是否 大于等于10.3 
        dothing();
    }
  }, false};
   element.addEventListener('change', function(e){
      if(!isComposition ) {
            dothing();
      }
  }, false};

参考资料

3. 使用弹窗的时候,遮罩层底部会随着滚动

解决方法:在点击弹窗的入口时设置页面高度为100%,消失的入口设置高度为auto

$scope.showMask = function{
  angular.element('html,body').css({overflow:'hidden', height: '100%'});
}
$scope.hideMask = function(){
  angular.element('html,body').css({overflow:'auto', height: 'auto'});
}

4.在当前页面滑动列表的时候点返回按钮,上一页的页面整体往上移动了

解决方法:在回到上一页时,使用$timeout()重新设置样式

$timeout(function(){
  angular.element('html,body').css({height: '100%'})
}, 0);

5.手机输入框输入中文时,输入框会显示中文拼音+中文

解决方法:对输入框进行复合事件监听(IME)

let lock = false;
angular.element('input').bind('compositionstart', function(e){
  lock=true;
}).bind('compositionend', function(e){
  lock=false;
}).bind('input', function(e){
  if(lock) return ;
  doanything();
});

6. 当列表数据过多,用户选中的数据未显示在屏幕内,即用户需要滑动才能看见所选中的数据

解决方法:使用scrollIntoView()方法(javascript高级程序设计第三版304页声明所有浏览器都已实现该方法)

msforest commented 7 years ago

桌面端问题

msforest commented 7 years ago

angular问题

1.使用$watch()监听对象没有进行实时更新

$scope.$watch('obj', function(newVal, oldVal){
  ...
}); //没有设置第三个参数

因为obj是scope里的一个对象,对对象进行监听的时候,需要加上第三个参数,表示使用angular.equals方法比较;如果是对基本类型监听,无需加入第三个参数;省略第三个参数有利于提示应用的性能。$watch参考

msforest commented 7 years ago

javascript问题

1. RangeError: Invalid string length

出现这种问题是因为在服务器返回的数据太多,转换后的字符串长度超过了2^28。为什么会有长度限制?个人认为是因为字符串是直接保存在内存中,而js可利用的内存大小是有限的。而express框架在传输对象的时候,会先使用JSON转换,此时数据还没到前端。 image

数组最大长度 既然字符串有长度限制,那数组呢,有没有最大长度? MDN给出了明确的答案:

参考链接

msforest commented 7 years ago

css问题

1.对规定长度的div,内容过长自动溢出而没有换行

<div class='test'>safjaskflasjfklsajfklasjflksajflksjflkasfdsafdsfksafj</div>
.test{
  width:30px;
  border:1px solid red;
  word-break: break-all;  //允许在单词内换行(后加)
}
msforest commented 6 years ago

webpack

1. webpack-dev-server热更新失效

解决办法
修改系统的fs.inotify.max_user_watches的值,可以使用下列两种办法来修改
方法一: 使用Shell命令直接修改
sudo sysctl fs.inotify.max_user_watches=524288

方法二: 修改sysctl.conf配置文件
sudo vim /etc/sysctl.conf
在文件的末尾加上
fs.inotify.max_user_watches=524288
重新从配置文件“/etc/sysctl.conf”加载内核参数设置
sudo sysctl -p /etc/sysctl.conf

我们可以通过下面的shell命令来查看Inotify监控文件的最大数量:
sysctl -a | grep inotify
msforest commented 6 years ago

linux

ssh连接超时问题

  1. 修改server端的etc/ssh/sshd_config

ClientAliveInterval 60 #server每隔60秒发送一次请求给client,然后client响应,从而保持连接 ClientAliveCountMax 3 #server发出请求后,客户端没有响应得次数达到3,就自动断开连接,正常情况下,client不会不响应

  1. 修改client端的etc/ssh/ssh_config添加以下:(在没有权限改server配置的情形下)

ServerAliveInterval 60 #client每隔60秒发送一次请求给server,然后server响应,从而保持连接 ServerAliveCountMax 3 #client发出请求后,服务器端没有响应得次数达到3,就自动断开连接,正常情况下,server不会不响应

  1. ssh参数设置:

不修改配置文件 在命令参数里ssh -o ServerAliveInterval=60 这样子只会在需要的连接中保持持久连接, 毕竟不是所有连接都要保持持久的