js技巧5

来源:互联网 发布:软件线报分享 编辑:程序博客网 时间:2024/06/04 01:20
[html] view plaincopyprint?
  1. 151.实现打印预览及打印 
  2. <OBJECT classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"height=0id=wbname=wbwidth=0></OBJECT> 
  3. <inputtype=buttonvalue=打印预览 onclick="wb.execwb(7,1)"> 
  4. <input type=buttononClick=document.all.wb.ExecWB(6,1)value="打印">// 
  5.   
  6. 152.不通过form,直接通过名字引用对象 
  7. <INPUTTYPE="text"NAME="gg"value=aaaaa> 
  8. <SCRIPT LANGUAGE="JavaScript"> 
  9. <!-- 
  10. alert(document.all.gg.value) 
  11. //--> 
  12. </SCRIPT>// 
  13.   
  14. 153.使鼠标滚轮失效 
  15. function document.onmousewheel() 
  16. return false; 
  17. }// 
  18.    
  19. 154.创建弹出窗口 
  20. <SCRIPTLANGUAGE="JScript"> 
  21.   var oPopup = window.createPopup(); 
  22.   var oPopupBody = oPopup.document.body; 
  23.   oPopupBody.innerHTML = "Display some <B>HTML</B> here."
  24.   oPopup.show(100, 100, 200, 50, document.body); 
  25. </SCRIPT>// 
  26.   
  27. 155.取得鼠标所在处的对象 
  28. var obj = document.elementFromPoint(event.x,event.y);// 
  29.   
  30. 156.获得左边的对象 
  31. <INPUT TYPE="text"NAME="gg"><INPUTTYPE="text"NAME="bb" 
  32.   
  33. onclick="this.previousSibling.value='guoguo'">// 
  34.   
  35. 157.定位鼠标 
  36. document.all.hint_layer.style.left  =event.x+document.body.scrollLeft+10; 
  37. document.all.hint_layer.style.top  =event.y+document.body.scrollTop+10;// 
  38.   
  39. 158.向下拉框指定位置添加项目 
  40. var op  = document.createElement("OPTION"); 
  41. document.all.selected_items.children(index).insertAdjacentElement("BeforeBegin",op); 
  42. op.text  = document.all.all_items[i].text; 
  43. op.value = document.all.all_items[i].value;// 
  44.   
  45.    
  46. 159.判断一个窗口是否已经打开,如果已经打开,则关闭之 
  47. var a; 
  48. if(a) 
  49. a.close(); 
  50. else 
  51. a=window.open('','','');// 
  52.   
  53. 160.动态创建一个标签 
  54. newElem  = document.createElement("DIV"); 
  55. newElem.id = "hint_layer"
  56. document.body.appendChild(newElem); 
  57. document.all.hint_layer.innerText="guoguo";// 
  58.   
  59. 161.标题栏 
  60. document.title// 
  61.   
  62. 162.背景图片 
  63. <body style="BACKGROUND-ATTACHMENT: fixed"background="img/bgfix.gif"></body>//背景图片不动 
  64.   
  65. <STYLE TYPE="text/css"> 
  66. <!-- 
  67. BODY {background-image:img/bgchild.jpg; 
  68. background-position: center; 
  69. background-repeat: no-repeat; 
  70. background-attachment: fixed;} 
  71. --> 
  72. </STYLE>//背景图片居中 
  73.   
  74. 163.设置透明效果 
  75. document.form.xxx.filters.alpha.opacity=0~100// 
  76.   
  77. 164.定义方法 
  78. var dragapproved=false
  79. document.onmouseup=new Function("dragapproved =false");// 
  80.    
  81. 165.将数字转化为人民币大写形式 
  82. function convertCurrency(currencyDigits) { 
  83. // Constants: 
  84. var MAXIMUM_NUMBER = 99999999999.99; 
  85. // Predefine the radix characters and currency symbols for output: 
  86. var CN_ZERO = "零"
  87. var CN_ONE = "壹"
  88. var CN_TWO = "贰"
  89. var CN_THREE = "叁"
  90. var CN_FOUR = "肆"
  91. var CN_FIVE = "伍"
  92. var CN_SIX = "陆"
  93. var CN_SEVEN = "柒"
  94. var CN_EIGHT = "捌"
  95. var CN_NINE = "玖"
  96. var CN_TEN = "拾"
  97. var CN_HUNDRED = "佰"
  98. var CN_THOUSAND = "仟"
  99. var CN_TEN_THOUSAND = "万"
  100. var CN_HUNDRED_MILLION ="亿"
  101. var CN_SYMBOL = "人民币"
  102. var CN_DOLLAR = "元"
  103. var CN_TEN_CENT = "角"
  104. var CN_CENT = "分"
  105. var CN_INTEGER = "整"
  106.    
  107. // Variables: 
  108. var integral; // Represent integral part of digit number. 
  109. var decimal; // Represent decimal part of digit number. 
  110. var outputCharacters; // The output result. 
  111. var parts; 
  112. var digits, radices, bigRadices, decimals; 
  113. var zeroCount; 
  114. var i, p, d; 
  115. var quotient, modulus; 
  116.    
  117. // Validate input string: 
  118. currencyDigits = currencyDigits.toString(); 
  119. if (currencyDigits == "") { 
  120.   alert("Empty input!"); 
  121.   return ""; 
  122. if (currencyDigits.match(/[^,.\d]/) != null) { 
  123.   alert("Invalid characters in the input string!"); 
  124.   return ""; 
  125. if ((currencyDigits).match(/^((\d{1,3}(,\d{3})*(.((\d{3},)*\d{1,3}))?)|(\d+(.\d+)?))$/) == null) { 
  126.   alert("Illegal format of digit number!"); 
  127.   return ""; 
  128.    
  129. // Normalize the format of input digits: 
  130. currencyDigits = currencyDigits.replace(/,/g, ""); // Remove comma delimiters. 
  131. currencyDigits = currencyDigits.replace(/^0+/, ""); // Trim zeros at the beginning. 
  132. // Assert the number is not greater than the maximum number. 
  133. if (Number(currencyDigits) > MAXIMUM_NUMBER) { 
  134.   alert("Too large a number to convert!"); 
  135.   return ""; 
  136.    
  137. // Process the coversion from currency digits to characters: 
  138. // Separate integral and decimal parts before processing coversion: 
  139. parts = currencyDigits.split("."); 
  140. if (parts.length > 1) { 
  141.   integral = parts[0]; 
  142.   decimal = parts[1]; 
  143.   // Cut down redundant decimal digits that are after the second. 
  144.   decimal = decimal.substr(0, 2); 
  145. else { 
  146.   integral = parts[0]; 
  147.   decimal = ""
  148. // Prepare the characters corresponding to the digits: 
  149. digits = new Array(CN_ZERO, CN_ONE, CN_TWO, CN_THREE, CN_FOUR, CN_FIVE, CN_SIX, CN_SEVEN, CN_EIGHT, 
  150.   
  151. CN_NINE); 
  152. radices = new Array("", CN_TEN, CN_HUNDRED, CN_THOUSAND); 
  153. bigRadices = new Array("", CN_TEN_THOUSAND, CN_HUNDRED_MILLION); 
  154. decimals = new Array(CN_TEN_CENT, CN_CENT); 
  155. // Start processing: 
  156. outputCharacters = ""
  157. // Process integral part if it is larger than 0: 
  158. if (Number(integral) > 0) { 
  159.   zeroCount = 0
  160.   for (i = 0; i< integral.length; i++) { 
  161.    p = integral.length - i - 1; 
  162.    d = integral.substr(i, 1); 
  163.    quotient = p / 4; 
  164.    modulus = p % 4; 
  165.    if (d == "0") { 
  166.     zeroCount++; 
  167.    } 
  168.    else { 
  169.     if (zeroCount > 0) 
  170.     { 
  171.      outputCharacters += digits[0]; 
  172.     } 
  173.     zeroCount = 0
  174.     outputCharacters += digits[Number(d)] + radices[modulus]; 
  175.    } 
  176.    if (modulus == 0 && zeroCount< 4) { 
  177.     outputCharacters += bigRadices[quotient]; 
  178.    } 
  179.   } 
  180.   outputCharacters += CN_DOLLAR; 
  181. // Process decimal part if there is: 
  182. if (decimal != "") { 
  183.   for (i = 0; i< decimal.length; i++) { 
  184.    d = decimal.substr(i, 1); 
  185.    if (d != "0") { 
  186.     outputCharacters += digits[Number(d)] + decimals[i]; 
  187.    } 
  188.   } 
  189. // Confirm and return the final output string: 
  190. if (outputCharacters == "") { 
  191.   outputCharacters = CN_ZERO + CN_DOLLAR; 
  192. if (decimal == "") { 
  193.   outputCharacters += CN_INTEGER; 
  194. outputCharacters = CN_SYMBOL + outputCharacters; 
  195. return outputCharacters; 
  196. }// 
  197.   
  198.    
  199. 166.xml数据岛绑定表格 
  200. <html> 
  201. <body> 
  202. <xmlid="abc"src="test.xml"></xml> 
  203. <table border='1'datasrc='#abc'> 
  204. <thead> 
  205. <td>接收人</td> 
  206. <td>发送人</td> 
  207. <td>主题</td> 
  208. <td>内容</td> 
  209. </thead> 
  210. <tfoot> 
  211. <tr><th>表格的结束</th></tr> 
  212. </tfoot> 
  213. <tr> 
  214. <td><divdatafld="to"></div></td> 
  215. <td><divdatafld="from"></div></td> 
  216. <td><divdatafld="subject"></div></td> 
  217. <td><divdatafld="content"></div></td> 
  218. </tr> 
  219. </table> 
  220. </body> 
  221. </html> 
  222.   
  223. //cd_catalog.xml 
  224. <?xmlversion="1.0"encoding="ISO-8859-1"?> 
  225. <!--  Edited with XML Spy v4.2
  226.   --> 
  227. <CATALOG> 
  228. <CD> 
  229.   <TITLE>Empire Burlesque</TITLE> 
  230.   <ARTIST>Bob Dylan</ARTIST> 
  231.   <COUNTRY>USA</COUNTRY> 
  232.   <COMPANY>Columbia</COMPANY> 
  233.   <PRICE>10.90</PRICE> 
  234.   <YEAR>1985</YEAR> 
  235.   </CD> 
  236. <CD> 
  237.   <TITLE>Hide your heart</TITLE> 
  238.   <ARTIST>Bonnie Tyler</ARTIST> 
  239.   <COUNTRY>UK</COUNTRY> 
  240.   <COMPANY>CBS Records</COMPANY> 
  241.   <PRICE>9.90</PRICE> 
  242.   <YEAR>1988</YEAR> 
  243.   </CD> 
  244. <CD> 
  245.   <TITLE>Greatest Hits</TITLE> 
  246.   <ARTIST>Dolly Parton</ARTIST> 
  247.   <COUNTRY>USA</COUNTRY> 
  248.   <COMPANY>RCA</COMPANY> 
  249.   <PRICE>9.90</PRICE> 
  250.   <YEAR>1982</YEAR> 
  251.   </CD> 
  252. <CD> 
  253.   <TITLE>Still got the blues</TITLE> 
  254.   <ARTIST>Gary Moore</ARTIST> 
  255.   <COUNTRY>UK</COUNTRY> 
  256.   <COMPANY>Virgin records</COMPANY> 
  257.   <PRICE>10.20</PRICE> 
  258.   <YEAR>1990</YEAR> 
  259.   </CD> 
  260. </CATALOG> 
  261. // 
  262.   
  263.   
  264. 167.以下组合可以正确显示汉字 
  265. ================================ 
  266. xml保存编码 xml页面指定编码 
  267. ANSI  gbk/GBK、gb2312 
  268. Unicode  unicode/Unicode 
  269. UTF-8  UTF-8 
  270. ================================ 
  271.   
  272.    
  273. 168.XML操作 
  274. <xmlid="xmldata"src="/data/books.xml"> 
  275. <div id="guoguo"></div> 
  276. <script> 
  277. var x=xmldata.recordset //取得数据岛中的记录集 
  278. if(x.absoluteposition < x.recordcount) //如果当前的绝对位置在最后一条记录之前 
  279. x.movenext();     //向后移动 
  280. x.moveprevious();    //向前移动 
  281. x.absoluteposition=1;   //移动到第一条记录 
  282. x.absoluteposition=x.recordcount;//移动到最后一条记录,注意记录集x.absoluteposition是从1到记录集记录的个 
  283.   
  284. 数的 
  285. guoguo.innerText=xmldso.recordset("field_name"); //从中取出某条记录 
  286. </script> 
原创粉丝点击