在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML5  HTML/ select()也有底線?

select()也有底線?

document.execCommand

當一個HTML文檔切換到設(shè)計模式(designMode)時,文檔對象暴露 execCommand方法,該方法允許運行命令來操縱可編輯區(qū)域的內(nèi)容。大多數(shù)命令影響文檔的選擇(粗體,斜體等),而其他命令插入新元素(添加鏈接)或影響整行(縮進)。當使用 contentEditable時,調(diào)用 execCommand() 將影響當前活動的可編輯元素。

相關(guān)的API可以參考MDN

<html>
<head>
</head>
<body>
    <form>
        <input type="text" id="myText" value="A cat played with a ball" style="width:5px">
        <input type="button" value="Select text" onclick="selText()"> 
    </form>
    <script type="text/javascript">
        function selText() {
              document.getElementById("myText").select();
              document.execCommand('copy' , true);
        }
    </script>
</body>
</html>

如上所示代碼,當寬度小于5px時,復(fù)制就沒有效果。

這是什么坑?

回答
編輯回答
亮瞎她

我用火狐,需要使用 document.execCommand('copy' , false)。寬度倒是沒影響。

2018年8月7日 20:40