日期:2014-05-18 浏览次数:20461 次
function getClipboard() { if (window.clipboardData) { return(window.clipboardData.getData('Text')); } else if (window.netscape) { netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); 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'); clip.getData(trans,clip.kGlobalClipboard); var str = new Object(); var len = new Object(); try { trans.getTransferData('text/unicode',str,len); } catch(error) { return null; } if (str) { if (Components.interfaces.nsISupportsWString) str=str.value.QueryInterface(Components.interfaces.nsISupportsWString); else if (Components.interfaces.nsISupportsString) str=str.value.QueryInterface(Components.interfaces.nsISupportsString); else str = null; } if (str) { return(str.data.substring(0,len.value / 2)); } } return null; } function test() { var str=getClipboard(); if(str!=null) { var list=str.split(" "); if(list.length>3) { document.getElementById("TextBox1").value=list[0]; document.getElementById("TextBox2").value=list[1]; document.getElementById("TextBox3").value=list[2]; document.getElementById("TextBox4").value=list[3]; } } }
------解决方案--------------------
var list=str.split(" ");
------------------------------
上面的split自己写一个分割字符串的函数,然后添加到var list=new Array();中