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

首頁 > 數據庫 > SQL Server > 正文

[js]javascript與剪貼板交互

2020-07-25 13:38:38
字體:
來源:轉載
供稿:網友
1.怎樣操作剪貼板,從而實現復制、剪切與粘貼?同時判斷剪貼板里邊的數據是否是文本?
if (!IsClipboardFormatAvailable(CF_TEXT)) 
return; 
if (!OpenClipboard(hwndMain)) 
return; 

hglb = GetClipboardData(CF_TEXT); 
if (hglb != NULL) 

lptstr = GlobalLock(hglb); 
if (lptstr != NULL) 

// Call the application-defined ReplaceSelection 
// function to insert the text and repaint the 
// window. 

ReplaceSelection(hwndSelected, pbox, lptstr); 
GlobalUnlock(hglb); 


CloseClipboard(); 

2.可以使用javascript獲得windows剪貼板里的字符串嗎?
比如在網頁中實現點擊一個文本框 就把剪貼板里的字符粘貼進去

當然可以
<form> 
<p> 
<input name=txtSearch value=""> 
<input type=button value=Copy2Clip onclick='javascript: var textRange=txtSearch.createTextRange(); textRange.execCommand("Copy")'> 
</p> 
<p> 
<input name="copyto" type="text" id="copyto"> 
<input type=button value=PastefromClip onclick='javascript: var textRange=copyto.createTextRange(); textRange.execCommand("Paste")'> 
</p> 
</form> 

3.javascript和剪貼板的交互 

一般可以這樣將id為‘objid'的對象的內容copy到剪貼板

var rng = document.body.createTextRange();
        rng.moveToElementText(document.getElementById("objid"));
        rng.scrollIntoView();
        rng.select();
        rng.execCommand("Copy");
        rng.collapse(false);
   setTimeout("window.status=''",1800)

也可以用rng.execCommand("Past");將剪貼板的內容粘到光標當前位置。

內容參見msdn 的textRange對象。

不過,copy到剪貼板的都是不帶html標簽的,所有html標簽都將被過濾。


4.window.clipboardData.getData("Text") //可以獲得剪貼版的文字 
window.clipboardData.setData("Text","你的內容") //向剪貼板里寫文本信息

5.怎么判斷剪貼板中的數據是否為字符串而不是圖片或別的信息?

Private Sub Command1_Click() 
If Clipboard.GetFormat(vbCFText) Or Clipboard.GetFormat(vbCFRTF) Then 
MsgBox "ok" 
End If 
End Sub 





6.請問如何判斷剪貼板中不為空? 


一、

Eg 
判斷windows剪貼板里是否為空,沒有則讀取圖片到Image中 
uses clipbrd; 

if ClipBoard.HasFormat(CF_Picture) then 
Image1.Picture.Assign(ClipBoard); 
   二、

uses Clipbrd; 

procedure TForm1.Button1Click(Sender: TObject); 
begin 
if Clipboard.FormatCount <= 0 then 
{ TODO : 空 }; 
end; 



7.怎樣確定剪貼板中的數據是否為圖象? 


GetFormat 方法示例 
本示例使用 GetFormat 方法確定 Clipboard 對象上數據的格式。要檢驗此示例,可將本例代碼粘貼到一個窗體的聲明部分,然后按 F5 鍵并單擊該窗體。 

Private Sub Form_Click () 
' 定義位圖各種格式。 
Dim ClpFmt, Msg ' 聲明變量。 
On Error Resume Next ' 設置錯誤處理。 
If Clipboard.GetFormat(vbCFText) Then ClpFmt = ClpFmt + 1 
If Clipboard.GetFormat(vbCFBitmap) Then ClpFmt = ClpFmt + 2 
If Clipboard.GetFormat(vbCFDIB) Then ClpFmt = ClpFmt + 4 
If Clipboard.GetFormat(vbCFRTF) Then ClpFmt = ClpFmt + 8 
Select Case ClpFmt 
Case 1 
Msg = "The Clipboard contains only text." 
Case 2, 4, 6 
Msg = "The Clipboard contains only a bitmap." 
Case 3, 5, 7 
Msg = "The Clipboard contains text and a bitmap." 
Case 8, 9 
Msg = "The Clipboard contains only rich text." 
Case Else 
Msg = "There is nothing on the Clipboard." 
End Select 
MsgBox Msg ' 顯示信息。 
End Sub 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 揭阳市| 开封市| 洛浦县| 页游| 普格县| 吉木萨尔县| 扎鲁特旗| 安多县| 威宁| 托克逊县| 扎赉特旗| 新昌县| 扎兰屯市| 汪清县| 海城市| 凉山| 宁河县| 文化| 会同县| 扎鲁特旗| 中山市| 巧家县| 霍城县| 阿拉善盟| 六安市| 沙洋县| 化州市| 海南省| 长泰县| 黎城县| 泉州市| 桐庐县| 右玉县| 清镇市| 永州市| 牡丹江市| 方山县| 梁山县| 龙门县| 玛纳斯县| 连山|