欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

js復(fù)制內(nèi)容到剪貼板代碼,js復(fù)制代碼的簡(jiǎn)單實(shí)例

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

如下所示:

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

js復(fù)制無非是以下三步:

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

2、全選對(duì)象的內(nèi)容:e.select()

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

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

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

2、參數(shù)詳解:

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

//相當(dāng)于單擊文件中的打開按鈕
document.execCommand(”O(jiān)pen”);
 
//將當(dāng)前頁(yè)面另存為
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);
 
//設(shè)置前景顏色;
document.execCommand(”ForeColor”,”false”,sColor);
 
//使絕對(duì)定位的對(duì)象可直接拖動(dòng);
document.execCommand(”2D-Position”,”false”,”true”);
 
//使對(duì)象定位變成絕對(duì)定位;
document.execCommand(”AbsolutePosition”,”false”,”true”);
 
//設(shè)置背景顏色;
document.execCommand(”BackColor”,”false”,sColor);
 
//使選中區(qū)域的文字加粗;
document.execCommand(”Bold”,”false”,null);
 
//復(fù)制選中的文字到剪貼板;
document.execCommand(”Copy”,”false”,null);
 
//設(shè)置指定錨點(diǎn)為書簽;
document.execCommand(”CreateBookmark”,”false”,sAnchorName);
 
//將選中文本變成超連接,若第二個(gè)參數(shù)為true,會(huì)出現(xiàn)參數(shù)設(shè)置對(duì)話框;
document.execCommand(”CreateLink”,”false”,sLinkURL);
 
//設(shè)置當(dāng)前塊的標(biāo)簽名;
document.execCommand(”FormatBlock”,”false”,sTagName);
 
//相當(dāng)于單擊文件中的打開按鈕
document.execCommand(”O(jiān)pen”);
 
//將當(dāng)前頁(yè)面另存為
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);
 
//設(shè)置前景顏色;
document.execCommand(”ForeColor”,”false”,sColor);
 
//使絕對(duì)定位的對(duì)象可直接拖動(dòng);
document.execCommand(”2D-Position”,”false”,”true”);
 
//使對(duì)象定位變成絕對(duì)定位;
document.execCommand(”AbsolutePosition”,”false”,”true”);
 
//設(shè)置背景顏色;
document.execCommand(”BackColor”,”false”,sColor);
 
//使選中區(qū)域的文字加粗;
document.execCommand(”Bold”,”false”,null);
 
//復(fù)制選中的文字到剪貼板;
document.execCommand(”Copy”,”false”,null);
 
//設(shè)置指定錨點(diǎn)為書簽;
document.execCommand(”CreateBookmark”,”false”,sAnchorName);
 
//將選中文本變成超連接,若第二個(gè)參數(shù)為true,會(huì)出現(xiàn)參數(shù)設(shè)置對(duì)話框;
document.execCommand(”CreateLink”,”false”,sLinkURL);
 
//設(shè)置當(dāng)前塊的標(biāo)簽名;
document.execCommand(”FormatBlock”,”false”,sTagName);

注:火狐不支持此方法!

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

相關(guān)文章

最新評(píng)論