亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

 更新時間:2016年10月27日 10:20:51   投稿:jingxian  
下面小編就為大家?guī)硪黄猨s復制內容到剪貼板代碼,js復制代碼的簡單實例。小編覺得挺不錯的,現在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

如下所示:

<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("")函數將內容復制。

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

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

2、參數詳解:

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

//相當于單擊文件中的打開按鈕
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);
 
//將選中文本變成超連接,若第二個參數為true,會出現參數設置對話框;
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);
 
//將選中文本變成超連接,若第二個參數為true,會出現參數設置對話框;
document.execCommand(”CreateLink”,”false”,sLinkURL);
 
//設置當前塊的標簽名;
document.execCommand(”FormatBlock”,”false”,sTagName);

注:火狐不支持此方法!

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

相關文章

最新評論