推荐关注
Meteor
JSLint - a JavaScript code quality tool
jsFiddle
D3.js
WebStorm
推荐书目
JavaScript 权威指南第 5 版
Closure: The Definitive Guide
liudaqi

这段拷贝到剪贴板的 js,编辑器怎么提示很多语法不规范呢

  •  
  •   liudaqi · Dec 3, 2018 · 3461 views
    This topic created in 2728 days ago, the information mentioned may be changed or developed.

    试了一下功能正常,很多地方不符合语法规范了,编辑器显示这么多红色波浪线

    copy.png

    <button id="btn">点我复制</button>
    
    const btn = document.querySelector('#btn');
    btn.addEventListener('click',() => {
        const input = document.createElement('input');
        document.body.appendChild(input);
        input.setAttribute('value', '听说你想复制我');
        input.select();
        if (document.execCommand('copy')) {
            document.execCommand('copy');
            console.log('复制成功');
        }
     document.body.removeChild(input);
    })
    
    7 replies    2018-12-03 15:09:54 +08:00
    shintendo
        1
    shintendo  
       Dec 3, 2018   ❤️ 1
    const 和箭头函数都是 ES6 语法,可能你的编辑器默认按 ES5 检查
    liudaqi
        2
    liudaqi  
    OP
       Dec 3, 2018
    @shintendo 谢谢 是的,从 5.1 调到 6 就好了
    azh7138m
        3
    azh7138m  
       Dec 3, 2018
    这个 document.execCommand('copy') 两次是什么操作?
    no1xsyzy
        4
    no1xsyzy  
       Dec 3, 2018
    应该先 document.queryCommandEnabled('copy') 啊
    Sapp
        5
    Sapp  
       Dec 3, 2018
    你这个 if 真的迷...
    JoeoooLAI
        6
    JoeoooLAI  
       Dec 3, 2018
    我是进来凑凑热闹的。。。。不知道为什么看到 JS 我总觉得是奸商。。。
    wleexi
        7
    wleexi  
       Dec 3, 2018
    @azh7138m 检查当前的环境有无这个 API 吧。。有才执行
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2869 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 76ms · UTC 14:38 · PVG 22:38 · LAX 07:38 · JFK 10:38
    ♥ Do have faith in what you're doing.