Key code:
Jsutils = {selectedrange:function(EL) {// <summary> /// selected content ///Eg:selectedrange (document.getElementById (' 123 ')); // </summary> /// <param name= "El" > Need to select Objects </param> varBODY = document.body, range, sel;if(Document.createrange && window.getselection) {The //range object represents a contiguous range of documents, such as a user dragging a selected area with the mouse in a browser window. //selection is the current active selection (that is, the highlighted text). Range = Document.createrange (); sel = Window.getselection (); Sel.removeallranges ();Try{range.selectnodecontents (EL); Sel.addrange (range); }Catch(e) {Range.selectnode (EL); Sel.addrange (range); } }Else if(body.createtextrange) {range = Body.createtextrange (); Range.movetoelementtext (EL); Range.Select (); } } };
Ieuitls = {copyelectoclipboard: function (elecid) { ///<summary> ///only supports Internet Explorer's copy of HTML elements to the Clipboard ///</summary> ///<param name= "elecid" > Need to copy id</param> var obj = document.getElementById (elecid); if (obj) {jsutils.selectedrange (obj); Document.execcommand ( ' copy ' , true ); } } };
Implementation code:
function Copy () {///<summary> ///copy the latitude and longitude table data to the Clipboard ///</summary> //var RowIds = $ (" #list4 "). Jqgrid (' Getdataids '); //if (rowIds) { //var copydate = '; //for (var i = 0, j = rowids.length; I < J; i++) { // var currowdata = $ ("#list4"). Jqgrid (' GetRowData ', rowids[i]); //copydate + = currowdata[' lat '] + ' + currowdata[' lng ' + ' \ n '; //} //Ieuitls.copytexttoclipboard (copydate); //} Ieuitls.copyelectoclipboard ( ' list4 ' ); }
Copy and paste to Excel like:
Hope to be helpful!
[JavaScript] under IE, copy table and support paste into Excel