javascript小技巧(六)

  
  
  
  
  1. //书   
  2.  
  3. http://www.itpub.net/attachment.php?s=&postid=1894598   
  4. http://www.wrclub.net/down/listdown.aspx?id=1341   
  5. //操作EXECL   
  6.  
  7. <script language="javascript">   
  8. function jStartExcel() {   
  9. var xls = new ActiveXObject ( "Excel.Application" );   
  10. xls.visible = true;   
  11. var newBook = xls.Workbooks.Add;   
  12. newBook.Worksheets.Add;   
  13. newBook.Worksheets(1).Activate;   
  14. xls.ActiveWorkBook.ActiveSheet.PageSetup.Orientation = 2;   
  15. xls.ActiveWorkBook.ActiveSheet.PageSetup.PaperSize = 5;   
  16. newBook.Worksheets(1).Columns("A").columnwidth=50;   
  17. newBook.Worksheets(1).Columns("A").WrapText = true;   
  18. newBook.Worksheets(1).Columns("B").columnwidth=50;   
  19. newBook.Worksheets(1).Columns("B").WrapText = true;   
  20. newBook.Worksheets(1).Range("A1:B1000").NumberFormat = "0";   
  21. newBook.Worksheets(1).Range("A1:B1000").HorizontalAlignment = -4131;   
  22. newBook.Worksheets(1).Cells(1,1).Interior.ColorIndex="15";   
  23. newBook.Worksheets(1).Cells(1,1).value="First Column, First Cell";   
  24. newBook.Worksheets(1).Cells(2,1).value="First Column, Second Cell";   
  25. newBook.Worksheets(1).Cells(1,2).value="Second Column, First Cell";   
  26. newBook.Worksheets(1).Cells(2,2).value="Second Column, Second Cell";   
  27. newBook.Worksheets(1).Name="My First WorkSheet";   
  28. }   
  29. </script>   
  30.  
  31. //自定义提示条   
  32.  
  33.  
  34. <a href="#" title="这是提示">tip</a>   
  35. <script Language="JavaScript">   
  36. //***********默认设置定义.*********************   
  37. tPopWait=50;//停留tWait豪秒后显示提示。   
  38. tPopShow=5000;//显示tShow豪秒后关闭提示   
  39. showPopStep=20;   
  40. popOpacity=99;   
  41. //***************内部变量定义*****************   
  42. sPop=null;   
  43. curShow=null;   
  44. tFadeOut=null;   
  45. tFadeIn=null;   
  46. tFadeWaiting=null;   
  47. document.write("<style type='text/css'id='defaultPopStyle'>");   
  48. document.write(".cPopText {   background-color: #F8F8F5;color:#000000; border: 1px #000000 solid;font-color: font-size: 12px; padding-right: 4px; padding-left: 4px; height: 20px; padding-top: 2px; padding-bottom: 2px; filter: Alpha(Opacity=0)}");   
  49. document.write("</style>");   
  50. document.write("<div id='dypopLayer' style='position:absolute;z-index:1000;' class='cPopText'></div>");   
  51.  
  52. function showPopupText(){   
  53. var o=event.srcElement;   
  54. MouseX=event.x;   
  55. MouseY=event.y;   
  56. if(o.alt!=null && o.alt!=""){o.dypop=o.alt;o.alt=""};   
  57.         if(o.title!=null && o.title!=""){o.dypop=o.title;o.title=""};   
  58. if(o.dypop!=sPop) {   
  59. sPop=o.dypop;   
  60. clearTimeout(curShow);   
  61. clearTimeout(tFadeOut);   
  62. clearTimeout(tFadeIn);   
  63. clearTimeout(tFadeWaiting);   
  64. if(sPop==null || sPop=="") {   
  65. dypopLayer.innerHTML="";   
  66. dypopLayer.style.filter="Alpha()";   
  67. dypopLayer.filters.Alpha.opacity=0;   
  68. }   
  69. else {   
  70. if(o.dyclass!=null) popStyle=o.dyclass    
  71. else popStyle="cPopText";   
  72. curShow=setTimeout("showIt()",tPopWait);   
  73. }   
  74. }   
  75. }   
  76. function showIt(){   
  77. dypopLayer.className=popStyle;   
  78. dypopLayer.innerHTML=sPop;   
  79. popWidth=dypopLayer.clientWidth;   
  80. popHeight=dypopLayer.clientHeight;   
  81. if(MouseX+12+popWidth>document.body.clientWidth) popLeftAdjust=-popWidth-24   
  82. else popLeftAdjust=0;   
  83. if(MouseY+12+popHeight>document.body.clientHeight) popTopAdjust=-popHeight-24   
  84. else popTopAdjust=0;   
  85. dypopLayer.style.left=MouseX+12+document.body.scrollLeft+popLeftAdjust;   
  86. dypopLayer.style.top=MouseY+12+document.body.scrollTop+popTopAdjust;   
  87. dypopLayer.style.filter="Alpha(Opacity=0)";   
  88. fadeOut();   
  89. }   
  90. function fadeOut(){   
  91. if(dypopLayer.filters.Alpha.opacity<popOpacity) {   
  92. dypopLayer.filters.Alpha.opacity+=showPopStep;   
  93. tFadeOut=setTimeout("fadeOut()",1);   
  94. }   
  95. else {   
  96. dypopLayer.filters.Alpha.opacity=popOpacity;   
  97. tFadeWaiting=setTimeout("fadeIn()",tPopShow);   
  98. }   
  99. }   
  100. function fadeIn(){   
  101. if(dypopLayer.filters.Alpha.opacity>0) {   
  102. dypopLayer.filters.Alpha.opacity-=1;   
  103. tFadeIn=setTimeout("fadeIn()",1);   
  104. }   
  105. }   
  106. document.  
  107. </script>   
  108. //插入文字   
  109.  
  110. document.onclick =function(){    
  111. var oSource = window.event.srcElement;    
  112. if(oSource.tagName!="DIV")    
  113. return false;    
  114. var sel = document.selection;    
  115. if (sel!=null) {    
  116. var rng = sel.createRange();    
  117. if (rng!=null)    
  118. rng.pasteHTML("<font color=red>插入文字</font>");    
  119. }    
  120. }    
  121. //netscapte下操作xml   
  122.  
  123.  
  124. //判断键值   
  125.  
  126.  
  127. //禁止FSO   
  128.  
  129.  
  130. 1.注销组件   
  131. regsvr32 /u scrrun.dll   
  132. 2.修改PROGID    
  133. HKEY_CLASSES_ROOT\Scripting.FileSystemObject   
  134. Scripting.FileSystemObject   
  135. 3.对于使用object的用户,修改HKEY_CLASSES_ROOT\Scripting.   
  136.  
  137. //省略号   
  138.  
  139.  
  140. //检测media play版本   
  141.  
  142.  
  143.  
  144. //图象按比例   
  145.  
  146.  
  147.  
  148. //细线SELECT   
  149.  
  150.  
  151.  
  152. function getComputerName()   
  153. {   
  154. var objWMIService = GetObject("Winmgmts:root\cimv2");   
  155. for(e = new Enumerator(objWMIService) ; !e.atEnd() ; e.moveNext())   
  156. {   
  157.     var getComputer = e.item();   
  158.     return getComputer.Name;   
  159. }   
  160. }   
  161.  
  162.  
  163. //条件编译   
  164.  
  165.  
  166.  
  167.  
  168. <script language=javascript>   
  169. /*@cc_on @*/   
  170. /*@if (@_win32 && @_jscript_version>5)   
  171. function window.confirm(str)   
  172. {   
  173.      execScript("n = msgbox('"+ str +"', 257)""vbscript");   
  174.      return(n == 1);   
  175. }   
  176. @end @*/   
  177. </script>   
  178.  
  179.  
  180. //取得innerText   
  181.  
  182.  
  183. <SCRIPT LANGUAGE="JavaScript">   
  184. <!--   
  185. var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.4.0");   
  186. var currNode;   
  187. xmlDoc.async = false;   
  188. xmlDoc.async = false;   
  189. xmlDoc.loadXML("<TABLENAME>       你好你阿三     大法      司法等四               </TABLENAME>");   
  190. currNode = xmlDoc.documentElement;   
  191.       
  192.   var s = currNode.xml;   
  193.   var r = /\<([^\>\s]*?)[^\>]*?\>([^\<]*?)\<\/\1\>/   
  194.   var b = s.replace(r,"$2");   
  195.    alert(b);   
  196. //-->   
  197. </SCRIPT>   
  198. //mergeAttributes 复制所有读/写标签属性到指定元素。   
  199.  
  200. <SCRIPT>   
  201. function fnMerge(){   
  202. oSource.children[1].mergeAttributes(oSource.children[0]);   
  203. }   
  204. </SCRIPT>   
  205. <SPAN ID=oSource>   
  206. <DIV   
  207. ID="oDiv"   
  208. ATTRIBUTE1="true"   
  209. ATTRIBUTE2="true"   
  210. onclick="alert('click');"   
  211. onmouseover="this.style.color='#0000FF';"   
  212. onmouseout="this.style.color='#000000';"   
  213. >   
  214. This is a sample <B>DIV</B> element.   
  215. </DIV>   
  216. <DIV ID="oDiv2">   
  217. This is another sample <B>DIV</B> element.   
  218. </DIV>   
  219. </SPAN>   
  220. <INPUT   
  221. TYPE="button"   
  222. VALUE="Merge Attributes"   
  223. onclick="fnMerge()"   
  224. >   
  225.  
  226. <span style="border:1px solid #000000; position:absolute; overflow:hidden;" >   
  227. <select style="margin:-2px;">   
  228. <option>1111</option>   
  229. <option>11111111111111</option>   
  230. <option>111111111</option>   
  231. </select></span>   
  232.  
  233. //Import   
  234.  
  235.  
  236. function Import() {   
  237. for( var i=0; i<arguments.length; i++ ) {   
  238.   var file = arguments[i];   
  239.   if ( file.match(/\.js$/i))    
  240.     document.write('<script type=\"text/javascript\" src=\"' + file + '\"></sc' + 'ript>');   
  241.    else   
  242.     document.write('<style type=\"text/css\">@import \"' + file + '\" ;</style>');   
  243. }   
  244. };   
  245.  
  246. //js枚举   
  247.  
  248.  
  249. <script language="JavaScript">   
  250. <!--   
  251. //图片按比例缩放   
  252. var flag=false;   
  253. function DrawImage(ImgD){   
  254. var image=new Image();   
  255. var iwidth = 80;  //定义允许图片宽度   
  256. var iheight = 80;  //定义允许图片高度   
  257. image.src=ImgD.src;   
  258. if(image.width>0 && image.height>0){   
  259. flag=true;   
  260. if(image.width/image.height>= iwidth/iheight){   
  261.   if(image.width>iwidth){     
  262.    ImgD.width=iwidth;   
  263.    ImgD.height=(image.height*iwidth)/image.width;   
  264.    }else{   
  265.    ImgD.width=image.width;     
  266.    ImgD.height=image.height;   
  267.    }   
  268.    ImgD.alt=image.width+"×"+image.height;   
  269.    }   
  270. else{   
  271.   if(image.height>iheight){     
  272.    ImgD.height=iheight;   
  273.    ImgD.width=(image.width*iheight)/image.height;     
  274.    }else{   
  275.    ImgD.width=image.width;     
  276.    ImgD.height=image.height;   
  277.    }   
  278.    ImgD.alt=image.width+"×"+image.height;   
  279.    }   
  280. }   
  281. }    
  282. //-->   
  283. </script>   
  284. <img src=".." onload = "DrawImage(this)">   
  285.  
  286.  
  287.  
  288.  
  289. <IE:clientCaps ID="oClientCaps" style="{behavior:url(#default#clientcaps)}" />   
  290. <SCRIPT>   
  291. var flash="";   
  292.      WMPVersion= oClientCaps.getComponentVersion("{22D6F312-B0F6-11D0-94AB-0080C74C7E95}","ComponentID");    
  293.     if (WMPVersion != "") {   
  294.      flash = "";   
  295.     var version = WMPVersion.split(",");   
  296.     var i;   
  297.      for (i = 0; i < version.length; i++) {   
  298.       if (i != 0)   
  299.      flash += ".";   
  300.        flash += version[i];   
  301.      }   
  302.       document.write("您的Windows Media Player 版本是:"+flash+"<p>");   
  303.    }   
  304. </SCRIPT>   
  305.  
  306.  
  307.  
  308.  
  309. <DIV STYLE="width: 120px; height: 50px; border: 1px solid blue;   
  310.              overflow: hidden; text-overflow:ellipsis">   
  311. <NOBR>就是比如有一行文字,很长,表格内一行显示不下.</NOBR>   
  312. </DIV>   
  313.  
  314. <html>   
  315. <meta http-equiv="Content-Type" content="text/html; charset=gb2312">   
  316. <head>   
  317. <script language="javascript">   
  318. var ie   =navigator.appName=="Microsoft Internet Explorer"?true:false;   
  319.      
  320. function keyDown(e)   
  321. {   
  322. if(!ie)   
  323. {   
  324.   var nkey=e.which;   
  325.   var iekey='现在是ns浏览器';   
  326.   var realkey=String.fromCharCode(e.which);   
  327. }   
  328. if(ie)   
  329. {   
  330.   var iekey=event.keyCode;   
  331.   var nkey='现在是ie浏览器';   
  332.   var realkey=String.fromCharCode(event.keyCode);   
  333.   if(event.keyCode==32){realkey='\' 空格\''}   
  334.   if(event.keyCode==13){realkey='\' 回车\''}   
  335.   if(event.keyCode==27){realkey='\' Esc\''}   
  336.   if(event.keyCode==16){realkey='\' Shift\''}   
  337.   if(event.keyCode==17){realkey='\' Ctrl\''}   
  338.   if(event.keyCode==18){realkey='\' Alt\''}   
  339. }   
  340. alert('ns浏览器中键值:'+nkey+'\n'+'ie浏览器中键值:'+iekey+'\n'+'实际键为'+realkey);   
  341. }   
  342. document.onkeydown = keyDown;   
  343. </script>   
  344. </head>   
  345. <body>   
  346. //Javascript Document.   
  347. <hr>   
  348. <center>   
  349. <h3>请按任意一个键。。。。</h3>   
  350. </center>   
  351. </body>   
  352. </html>   
  353.  
  354. doc = new ActiveXObject("Msxml2.DOMDocument");   
  355. doc = new ActiveXObject("Microsoft.XMLDOM")   
  356. ->>   
  357. doc = (new DOMParser()).parseFromString(sXML,'text/xml')  

 

你可能感兴趣的:(JavaScript,开发,小技巧)