input 黏贴 onpaste 拿到新值

来源:互联网 发布:js div跟随滚动条滑动 编辑:程序博客网 时间:2024/05/18 02:33

onpaste,默认e.target.value ,拿到的时就值,如果需要那到黏贴后的值,需要setTimeout

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8"></head><body><div class="container" id="J_container">    <input type="text" onpaste="myFunction(event)" value="将新内容黏贴到这里">    <div  onclick="copyText(event)">点击测试</div></div><script>    function myFunction(e)    {         console.log(e.target.value);        setTimeout(function(){            console.log(e.target.value);        },0)    }</script></body></html>
0 0