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

首頁(yè) > 數(shù)據(jù)庫(kù) > SQL Server > 正文

[js]javascript與剪貼板交互

2024-08-31 01:00:00
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
1.怎樣操作剪貼板,從而實(shí)現(xiàn)復(fù)制、剪切與粘貼?同時(shí)判斷剪貼板里邊的數(shù)據(jù)是否是文本?
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剪貼板里的字符串嗎?
比如在網(wǎng)頁(yè)中實(shí)現(xiàn)點(diǎn)擊一個(gè)文本框 就把剪貼板里的字符粘貼進(jìn)去

當(dāng)然可以
<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'的對(duì)象的內(nèi)容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");將剪貼板的內(nèi)容粘到光標(biāo)當(dāng)前位置。

內(nèi)容參見msdn 的textRange對(duì)象。

不過(guò),copy到剪貼板的都是不帶html標(biāo)簽的,所有html標(biāo)簽都將被過(guò)濾。


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

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

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





6.請(qǐng)問(wèn)如何判斷剪貼板中不為空? 


一、

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.怎樣確定剪貼板中的數(shù)據(jù)是否為圖象? 


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

Private Sub Form_Click () 
' 定義位圖各種格式。 
Dim ClpFmt, Msg ' 聲明變量。 
On Error Resume Next ' 設(shè)置錯(cuò)誤處理。 
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 

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 凉山| 西丰县| 东丽区| 长武县| 云南省| 淮安市| 巴塘县| 湖北省| 宜君县| 禹城市| 施秉县| 西青区| 习水县| 罗城| 喜德县| 大方县| 万宁市| 南丰县| 黎平县| 芦溪县| 綦江县| 皋兰县| 黄大仙区| 双鸭山市| 临颍县| 林西县| 龙里县| 北安市| 白玉县| 化隆| 永和县| 佛山市| 都江堰市| 三亚市| 开平市| 彭阳县| 嫩江县| 洛隆县| 互助| 海淀区| 新安县|