執行 ❯
建立您
自己的
網站
×
更改方向
儲存程式碼
更改主題,深色/淺色
前往 Spaces
<!DOCTYPE html> <html> <body> <h1>Change user-select with JavaScript</h1> <p>Click the "Try it" button to set the user-select property of the p element to "none":</p> <button onclick="myFunction()">Try it</button> <p id="demo">After you click on the button, it is not possible to select the text of this p element (try to double-click me before and after).</p> <script> function myFunction() { var x = document.getElementById("demo"); x.style.WebkitUserSelect = "none"; // Safari x.style.msUserSelect = "none"; // IE 10 and IE11 x.style.userSelect = "none"; // Standard syntax } </script> </body> </html>