JS技巧

  1. 1.文本框焦點問題
  2. onBlur:當失去輸入焦點後產生該事件
  3. onFocus:當輸入獲得焦點後,產生該文件
  4. Onchange:當文字值改變時,產生該事件
  5. Onselect:當文字加亮後,產生該文件
  6. <input type="text" value="mm" onfocus="if(value=='mm) {value=''}" onblur="if
  7. (value=='') {value='mm'}">點擊時文字消失,失去焦點時文字再出現
  8. 2.網頁按鈕的特殊顏色
  9. <input type=button name="Submit1" value="郭強" size=10 class=s02
  10. style="background-color:rgb(235,207,22)">
  11. 3.鼠標移入移出時顏色變化
  12. <input type="submit" value="找吧" name="B1" onMouseOut=this.style.color="blue"
  13. onMouseOver=this.style.color="red" class="button">
  14. 4.平面按鈕
  15. <input type=submit value=訂閱 style="border:1px solid :#666666; height:17px; width:25pt; font-size:9pt;
  16. BACKGROUND-COLOR: #E8E8FF; color:#666666" name="submit">
  17. 5.按鈕顏色變化
  18. <input type=text name="nick" style="border:1px solid #666666; font-size:9pt; height:17px;
  19. BACKGROUND-COLOR: #F4F4FF; color:#ff6600" size="15" maxlength="16">
  20. 6.平面輸入框
  21. <input type="text" name="T1" size="20" style="border-style: solid; border-width: 1">
  22. 7.使窗口變成指定的大小
  23. <script>
  24. window.resizeTo(300,283);
  25. </script>
  26. 8.使文字上下滾動
  27. <marquee direction=up scrollamount=1 scrolldelay=100 onmouseover='this.stop()' onmouseout='this.start()'
  28. height=60>
  29. <!-- head_scrolltext -->
  30. <tr>
  31. <td>
  32. 共和國
  33. </table> <!-- end head_scrolltext -->
  34. </marquee>
  35. 9.狀態欄顯示該頁狀態
  36. <base onmouseover="window.status='網站建設 http://www.webmake.cn/' ;return true">
  37. 10.可以點擊文字實現radio選項的選定
  38. <input type="radio" name="regtype" value="A03" id="A03">
  39. <label for="A03"> 情侶 : 一次註冊兩個帳戶</label>
  40. 11.可以在文字域的font寫onclick事件
  41. 12.打印</a>打印網頁
  42. <a href='javascript:window.print ()'>
  43. 13.線型輸入框
  44. <input type="text" name="key" size="12" value="關鍵字" onFocus=this.select() onMouseOver=this.focus()
  45. class="line">
  46. 14.顯示文檔最後修改日期
  47. <script language=javascript>
  48. function hi(str)
  49. {
  50. document.write(document.lastModified)
  51. alert("hi"+str+"!")
  52. }
  53. </script>
  54. 15.可以在鼠標移到文字上時就觸發事件
  55. <html>
  56. <head>
  57. <script language="LiveScript">
  58. <!-- Hiding
  59. function hello() {
  60. alert("哈羅!");
  61. }
  62. </script>
  63. </head>
  64. <body>
  65. <a href="" onMouseOver="hello()">link</a>
  66. </body>
  67. </html>
  68. 16.可以根據網頁上的選項來確定頁面顏色
  69. <HTML>
  70. <HEAD>
  71. <TITLE>background.html</TITLE>
  72. </HEAD>
  73. <SCRIPT>
  74. <!--
  75. function bgChange(selObj) {
  76. newColor = selObj.options[selObj.selectedIndex].text;
  77. document.bgColor = newColor;
  78. selObj.selectedIndex = -1;
  79. }
  80. //-->
  81. </SCRIPT>
  82. <BODY STYLE="font-family:Arial">
  83. <B>Changing Background Colors</B>
  84. <FORM>
  85. <SELECT SIZE="8" onChange="bgChange(this);">
  86. <OPTION>Red
  87. <OPTION>Orange
  88. <OPTION>Yellow
  89. <OPTION>Green
  90. <OPTION>Blue
  91. <OPTION>Indigo
  92. <OPTION>Violet
  93. <OPTION>White
  94. <OPTION>pink
  95. </SELECT>
  96. </FORM>
  97. </BODY>
  98. </HTML>
  99. 17.將按鈕的特徵改變
  100. <style type="text/css">
  101. <!--
  102. .style1 { font-size: 12px; background: #CCCCFF; border-width: thin thin thin thin; border-color: #CCCCFF
  103. #CCCCCC #CCCCCC #CCCCFF}
  104. .style2 { font-size: 12px; font-weight: bold; background: #CCFFCC; border-width: thin medium medium thin;
  105. border-color: #CCFF99 #999999 #999999 #CCFF99}
  106. -->
  107. </style>
  108.   本例按鈕的代碼如下:
  109. <input type="submit" name="Submit" value="提 交" onmouseover="this.className='style2'"
  110. onmouseout="this.className='style1'" class="style1">
  111. 18.改變按鈕的圖片.
  112. <style type="text/css">
  113. <!--
  114. .style3 { font-size: 12px; background: url(image/buttonbg1.gif); border: 0px; width: 60px; height: 22px}
  115. .style4 { font-size: 12px; font-weight: bold; background: url(image/buttonbg2.gif); border: 0px 0; width:
  116. 60px; height: 22px}
  117. -->
  118. </style>
  119.   本例的按鈕代碼如下:
  120. <input type="submit" name="Submit2" value="提 交" onmouseover="this.className='style4'"
  121. onmouseout="this.className='style3'" class="style3">
  122. 19.打印頁面
  123. <div align="center"><a class=content href="javascript:doPrint();">打印本稿</a></div>
  124. 20.可以直接寫html語言
  125. document.write("");
  126. 21.改變下拉框的顏色
  127. <select name="classid"
  128. onChange="changelocation(document.myform.classid.options[document.myform.classid.selectedIndex].value)"
  129. size="1" style="color:#008080;font-size: 9pt">
  130. 22.轉至目標URL
  131. window.location="http://guoguo"
  132. 23.傳遞該object的form
  133. UpdateSN('guoqiang99267',this.form)
  134. function UpdateSN(strValue,strForm)
  135. {
  136. strForm.SignInName.value = strValue;
  137. return false;
  138. }
  139. 24.文字標籤
  140. <label for="AltName4"><input name="AltName" type="RADIO" tabindex="931" id="AltName4"
  141. >guoqiang99859</label>
  142. 25.layer2爲組件的ID,可以控制組件是否可見
  143. document.all.item('Layer2').style.display = "block";
  144. document.all.item('Layer2').style.display = "none";//
  145. 26.將頁面加入favorite中
  146. <script language=javascript>
  147. <!--
  148. function Addme(){
  149. url = "http://your.site.address"; //你自己的主頁地址
  150. title = "Your Site Name"; //你自己的主頁名稱
  151. window.external.AddFavorite(url,title);
  152. -->
  153. </script>//
  154. 27.過10秒自動關閉頁面
  155. < script language="JavaScript" >
  156. function closeit() {
  157. setTimeout("self.close()",10000)
  158. }
  159. < /script >
  160. 28.可以比較字符的大小
  161. char=post.charAt(i);
  162. if(!('0'<=char&&char<='9'))
  163. 29.將字符轉化爲數字
  164. month = parseInt(char)
  165. 30.點擊value非空的選項時轉向指定連接
  166. <select onchange='if(this.value!="")window.open(this.value)' class="textinput">
  167. <option selected>主辦單位</option>
  168. <option>-----------------</option>
  169. <option value="http://www.bjd.com.cn/">北京日報</option>
  170. <option value="http://www.ben.com.cn/">北京晚報</option>
  171. </select>
  172. 31.改變背景顏色
  173. <td width=* class=dp bgColor=#FAFBFC onmouseover="this.bgColor='#FFFFFF';"
  174. onmouseout="this.bgColor='#FAFBFC';">
  175. 32.改變文字輸入框的背景顏色
  176. <style>
  177. .input2 {background-image: url('../images/inputbg.gif'); font-size: 12px; background-color:
  178. #D0DABB;border-top-width:1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px}
  179. </style>
  180. <input name=content type=text size="47" class="input2" maxlength="50">
  181. 33.改變水平線的特徵
  182. <hr size="0" noshade color="#C0C0C0">
  183. 34.傳遞參數的方式
  184. <a href="vote.asp?CurPage=8&id=3488">8</a>
  185. 35.頁內跳轉
  186. <a href="#1">1</a>
  187. <a href="#2">2</a>
  188. <a href="#3">3</a>
  189. <a href="#4">4</a>
  190. <a href="#5">5</a>
  191. <a href="#6">6</a>
  192. <a href="#7">7</a>
  193. <a name="1">dfdf</a>
  194. <a name="2">dfdf</a>//
  195. 36.兩個按鍵一起按下
  196. if(event.ctrlKey && window.event.keyCode==13)//
  197. 37.刷新頁面
  198. javascript:this.location.reload()//
  199. 38.將網頁的按鈕使能
  200. <SCRIPT LANGUAGE="JavaScript">
  201. function haha()
  202. {
  203. for(var i=0;i<document.form1.elements.length;i++)
  204. {
  205. if(document.form1.elements[i].name.indexOf("bb")!=-1)
  206. document.form1.elements[i].disabled=!document.form1.elements[i].disabled;
  207. }
  208. }
  209. </SCRIPT>
  210. <BODY><form name=form1>
  211. <INPUT TYPE="button" NAME="aa " value=cindy onclick=haha()>
  212. <INPUT TYPE="button" NAME="bb " value=guoguo>
  213. <INPUT TYPE="button" NAME="bb " value=guoguo>
  214. 39.文字移動
  215. <marquee scrollamount=3 onmouseover=this.stop(); onmouseout=this.start();>
  216. 40.雙擊網頁自動跑
  217. <SCRIPT LANGUAGE="JavaScript">
  218. var currentpos,timer;
  219. function initialize()
  220. {
  221. timer=setInterval("scrollwindow()",1);
  222. }
  223. function sc()
  224. {
  225. clearInterval(timer);
  226. }
  227. function scrollwindow()
  228. {
  229. currentpos=document.body.scrollTop;
  230. window.scroll(0,++currentpos);
  231. if (currentpos != document.body.scrollTop)
  232. sc();
  233. }
  234. document.onmousedown=sc
  235. document.ondblclick=initialize
  236. </SCRIPT>//
  237. 41.後退
  238. <INPUT TYPE="button" onclick=window.history.back() value=back>
  239. 42.前進
  240. <INPUT TYPE="button" onclick=window.history.forward() value=forward>
  241. 43.刷新
  242. <INPUT TYPE="button" onclick=document.location.reload() value=reload>
  243. 44.轉向指定網頁
  244. document.location="http://ww"或者document.location.assign("http://guoguo.com")
  245. 45.在網頁上顯示實時時間
  246. <SCRIPT LANGUAGE="JavaScript">
  247. var clock_id;
  248. window.onload=function()
  249. {
  250. clock_id=setInterval("document.form1.txtclock.value=(new Date);",1000)
  251. }
  252. </SCRIPT>//
  253. 46.可以下載文件
  254. document.location.href="目標文件"//
  255. 47.連接數據庫
  256. import java.sql.*;
  257. String myDBDriver="sun.jdbc.odbc.JdbcOdbcDriver";
  258. Class.forName(myDBDriver);
  259. Connection conn=DriverManager.getConnection("jdbc:odbc:firm","username","password");
  260. Statement stmt=conn.createStatement();
  261. ResultSet rs=stmt.executeQuery(sql);
  262. rs.getString("column1");//
  263. 48.可以直接在頁面“div”內寫下所需內容
  264. <INPUT TYPE="button" onclick="a1.innerHTML='<font color=red>*</font>'">
  265. <div id=a1></div>//
  266. 49.可以改變頁面上的連接的格式,使其爲雙線
  267. <style>
  268. A:link {text-decoration: none; color:#0000FF; font-family: 宋體}
  269. A:visited {text-decoration: none; color: #0000FF; font-family: 宋體}
  270. A:hover {text-decoration: underline overline; color: FF0000}
  271. </style>
  272. <style>
  273. A:link {text-decoration: none; color:#0000FF; font-family: 宋體}
  274. A:visited {text-decoration: none; color: #0000FF; font-family: 宋體}
  275. A:hover {text-decoration: underline overline line-through; color: FF0000}
  276. TH{FONT-SIZE: 9pt}
  277. TD{FONT-SIZE: 9pt}
  278. body {SCROLLBAR-FACE-COLOR: #A9D46D; SCROLLBAR-HIGHLIGHT-COLOR: #e7e7e7;SCROLLBAR-SHADOW-COLOR:#e7e7e7;
  279. SCROLLBAR-3DLIGHT-COLOR: #000000; LINE-HEIGHT: 15pt; SCROLLBAR-ARROW-COLOR: #ffffff;
  280. SCROLLBAR-TRACK-COLOR: #e7e7e7;}
  281. INPUT{BORDER-TOP-WIDTH: 1px; PADDING-RIGHT: 1px; PADDING-LEFT: 1px; BORDER-LEFT-WIDTH: 1px; FONT-SIZE:
  282. 9pt; BORDER-LEFT-COLOR: #cccccc;
  283. BORDER-BOTTOM-WIDTH: 1px; BORDER-BOTTOM-COLOR: #cccccc; PADDING-BOTTOM: 1px; BORDER-TOP-COLOR: #cccccc;
  284. PADDING-TOP: 1px; HEIGHT: 18px; BORDER-RIGHT-WIDTH: 1px; BORDER-RIGHT-COLOR: #cccccc}
  285. DIV,form ,OPTION,P,TD,BR{FONT-FAMILY: 宋體; FONT-SIZE: 9pt}
  286. textarea, select {border-width: 1; border-color: #000000; background-color: #efefef; font-family: 宋體;
  287. font-size: 9pt; font-style: bold;}
  288. .text { font-family: "宋體"; font-size: 9pt; color: #003300; border: #006600 solid; border-width: 1px 1px
  289. 1px 1px}
  290. </style>完整的css
  291. 50.新建frame
  292. <a
  293. href="javascript:newframe('http://www.163.net/help/a_little/index.html','http://www.163.net/help/a_little
  294. /a_13.html')"><img alt=幫助 border=0 src="http://bjpic.163.net/images/mail/button-help.gif"></a>
發佈了31 篇原創文章 · 獲贊 3 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章