国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

js復制內容到剪貼板代碼,js復制代碼的簡單實例

2019-11-20 08:39:04
字體:
來源:轉載
供稿:網(wǎng)友

如下所示:

<script type="text/JavaScript">   function jsCopy(){     var e=document.getElementById("contents");//對象是contents     e.select(); //選擇對象     document.execCommand("Copy"); //執(zhí)行瀏覽器復制命令  } </script> <textarea id="contents" cols="40" rows="5"></textarea><br /><input type="button" onClick="jsCopy();" value="復制" />

js復制無非是以下三步:

1、獲取復制的對象:document.getElementById("contents")這句話就是獲取ID=“contents”的textarea。

2、全選對象的內容:e.select()

3、用execCommand("")函數(shù)將內容復制。

下面來詳細介紹execCommand("")函數(shù)的參數(shù):

1、格式:document.execCommand(sCommand[,交互方式, 動態(tài)參數(shù)])

2、參數(shù)詳解:

1、〖全選〗命令的實現(xiàn)
[格式]:document.execCommand(”selectAll”)
[說明]將選種網(wǎng)頁中的全部內容!
 
2、〖打開〗命令的實現(xiàn)
[格式]:document.execCommand(”open”)
[說明]這跟VB等編程設計中的webbrowser控件中的命令有些相似,大家也可依此琢磨琢磨。
 
3、〖另存為〗命令的實現(xiàn)
[格式]:document.execCommand(”saveAs”)
[說明]將該網(wǎng)頁保存到本地盤的其它目錄!
 
4、〖打印〗命令的實現(xiàn)
[格式]:document.execCommand(”print”)
[說明]當然,你必須裝了打印機!
 
Js代碼下面列出的是指令參數(shù)及意義

//相當于單擊文件中的打開按鈕document.execCommand(”O(jiān)pen”); //將當前頁面另存為document.execCommand(”SaveAs”); //剪貼選中的文字到剪貼板;document.execCommand(”Cut”,”false”,null); //刪除選中的文字;document.execCommand(”Delete”,”false”,null); //改變選中區(qū)域的字體;document.execCommand(”FontName”,”false”,sFontName); //改變選中區(qū)域的字體大小;document.execCommand(”FontSize”,”false”,sSize|iSize); //設置前景顏色;document.execCommand(”ForeColor”,”false”,sColor); //使絕對定位的對象可直接拖動;document.execCommand(”2D-Position”,”false”,”true”); //使對象定位變成絕對定位;document.execCommand(”AbsolutePosition”,”false”,”true”); //設置背景顏色;document.execCommand(”BackColor”,”false”,sColor); //使選中區(qū)域的文字加粗;document.execCommand(”Bold”,”false”,null); //復制選中的文字到剪貼板;document.execCommand(”Copy”,”false”,null); //設置指定錨點為書簽;document.execCommand(”CreateBookmark”,”false”,sAnchorName); //將選中文本變成超連接,若第二個參數(shù)為true,會出現(xiàn)參數(shù)設置對話框;document.execCommand(”CreateLink”,”false”,sLinkURL); //設置當前塊的標簽名;document.execCommand(”FormatBlock”,”false”,sTagName); //相當于單擊文件中的打開按鈕document.execCommand(”O(jiān)pen”); //將當前頁面另存為document.execCommand(”SaveAs”); //剪貼選中的文字到剪貼板;document.execCommand(”Cut”,”false”,null); //刪除選中的文字;document.execCommand(”Delete”,”false”,null); //改變選中區(qū)域的字體;document.execCommand(”FontName”,”false”,sFontName); //改變選中區(qū)域的字體大小;document.execCommand(”FontSize”,”false”,sSize|iSize); //設置前景顏色;document.execCommand(”ForeColor”,”false”,sColor); //使絕對定位的對象可直接拖動;document.execCommand(”2D-Position”,”false”,”true”); //使對象定位變成絕對定位;document.execCommand(”AbsolutePosition”,”false”,”true”); //設置背景顏色;document.execCommand(”BackColor”,”false”,sColor); //使選中區(qū)域的文字加粗;document.execCommand(”Bold”,”false”,null); //復制選中的文字到剪貼板;document.execCommand(”Copy”,”false”,null); //設置指定錨點為書簽;document.execCommand(”CreateBookmark”,”false”,sAnchorName); //將選中文本變成超連接,若第二個參數(shù)為true,會出現(xiàn)參數(shù)設置對話框;document.execCommand(”CreateLink”,”false”,sLinkURL); //設置當前塊的標簽名;document.execCommand(”FormatBlock”,”false”,sTagName);

注:火狐不支持此方法!

以上就是小編為大家?guī)淼膉s復制內容到剪貼板代碼,js復制代碼的簡單實例全部內容了,希望大家多多支持武林網(wǎng)~

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 高密市| 农安县| 长兴县| 府谷县| 买车| 秭归县| 白沙| 婺源县| 平塘县| 平南县| 平泉县| 新晃| 长寿区| 庆阳市| 牟定县| 宝兴县| 新巴尔虎左旗| 水城县| 达拉特旗| 牙克石市| 仙游县| 嘉祥县| 禄劝| 建始县| 武定县| 淄博市| 溆浦县| 独山县| 堆龙德庆县| 广南县| 盐池县| 龙山县| 涞水县| 辰溪县| 辉县市| 留坝县| 和田市| 左贡县| 横峰县| 天镇县| 新河县|