This article illustrates a simple jquery implementation method of clicking a text box to copy content onto the Clipboard. Share to everyone for your reference, specific as follows:
Click the text box to copy its contents to the Clipboard method function CopyToClipboard (TXT) {if (window.clipboarddata) {window.clipboardData.clearData ();
Window.clipboardData.setData ("Text", txt); Alert ("has been successfully copied to the Clipboard!")
");
else if (navigator.userAgent.indexOf ("Opera")!=-1) {window.location = txt;
else if (Window.netscape) {try {netscape.security.PrivilegeManager.enablePrivilege ("Universalxpconnect"); catch (E) {alert ("Rejected by browser!")
\ nplease type ' About:config ' in the browser address bar and enter \ n then set ' Signed.applets.codebase_principal_support ' to ' true '); var clip = components.classes[' @mozilla. Org/widget/clipboard;1 '].createinstance (
Components.interfaces.nsIClipboard);
if (!clip) return; var trans = components.classes[' @mozilla. Org/widget/transferable;1 '].createinstance (
Components.interfaces.nsITransferable);
if (!trans) return;
Trans.adddataflavor (' Text/unicode ');
var str = new Object ();
var len = new Object (); var str = components.classes["@mozilla. Org/supports-string;1"].creAteinstance (Components.interfaces.nsISupportsString);
var copytext = txt;
Str.data = CopyText;
Trans.settransferdata ("Text/unicode", str, copytext.length * 2);
var clipid = Components.interfaces.nsIClipboard;
if (!clip) return false;
Clip.setdata (trans, NULL, Clipid.kglobalclipboard); Alert ("has been successfully copied to the Clipboard!")
"); //Click the text box to copy its contents to the Clipboard function Setcopylink () {$ ("#txt_CopyLink"). Val (document.
URL). focus (function () {$ (this). css ({"Background-color": "#ddd"}). Select ();
CopyToClipboard ($ ("#txt_CopyLink"). Val ());
}). blur (function () {$ (this). css ({"Background-color": "#fff"});
});
}
More interested readers of jquery related content can view the site topics: "JQuery common event usage and skill summary", "jquery form Operation skill Summary", "jquery common Plug-ins and Usage summary", "jquery operation JSON data technique summary", " jquery Extension Tips Summary, jquery table (table) Operation tips Summary, jquery Common Classic effects summary, jquery animation and special effects usage summary and jquery selector Usage Summary
I hope this article will help you with the jquery program design.