JS技巧

来源:互联网 发布:网络整合营销推广 编辑:程序博客网 时间:2024/06/16 06:21
Javajavascriptjsp技巧语言
[html] view plaincopyprint?
  1. 1.文本框焦点问题
  2. onBlur:当失去输入焦点后产生该事件
  3. onFocus:当输入获得焦点后,产生该文件
  4. Onchange:当文字值改变时,产生该事件
  5. Onselect:当文字加亮后,产生该文件
  6. <inputtype="text"value="mm"onfocus="if(value=='mm) {value=''}"onblur="if
  7. (value=='') {value='mm'}">点击时文字消失,失去焦点时文字再出现
  8. 2.网页按钮的特殊颜色
  9. <input type=buttonname="Submit1"value="郭强"size=10class=s02
  10. style="background-color:rgb(235,207,22)">
  11. 3.鼠标移入移出时颜色变化
  12. <inputtype="submit"value="找吧"name="B1"onMouseOut=this.style.color="blue"
  13. onMouseOver=this.style.color="red"class="button">
  14. 4.平面按钮
  15. <input type=submitvalue=订阅 style="border:1px solid :#666666; height:17px; width:25pt; font-size:9pt;
  16. BACKGROUND-COLOR: #E8E8FF; color:#666666" name="submit">
  17. 5.按钮颜色变化
  18. <inputtype=textname="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=upscrollamount=1scrolldelay=100onmouseover='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. <baseonmouseover="window.status='网站建设 http://www.webmake.cn/' ;return true">
  37. 10.可以点击文字实现radio选项的选定
  38. <inputtype="radio"name="regtype"value="A03"id="A03">
  39. <label for="A03"> 情侣 : 一次注册两个帐户</label>
  40. 11.可以在文字域的font写onclick事件
  41. 12.打印</a>打印网页
  42. <ahref='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. <scriptlanguage=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. <scriptlanguage="LiveScript">
  58. <!-- Hiding
  59. function hello() {
  60. alert("哈罗!");
  61. }
  62. </script>
  63. </head>
  64. <body>
  65. <ahref=""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. <BODYSTYLE="font-family:Arial">
  83. <B>Changing Background Colors</B>
  84. <FORM>
  85. <SELECTSIZE="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. <styletype="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. <styletype="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. <divalign="center"><aclass=contenthref="javascript:doPrint();">打印本稿</a></div>
  124. 20.可以直接写html语言
  125. document.write("");
  126. 21.改变下拉框的颜色
  127. <selectname="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. <labelfor="AltName4"><inputname="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. < scriptlanguage="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. <optionvalue="http://www.bjd.com.cn/">北京日报</option>
  170. <option value="http://www.ben.com.cn/">北京晚报</option>
  171. </select>
  172. 31.改变背景颜色
  173. <td width=* class=dpbgColor=#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=contenttype=textsize="47"class="input2"maxlength="50">
  181. 33.改变水平线的特征
  182. <hrsize="0" noshadecolor="#C0C0C0">
  183. 34.传递参数的方式
  184. <a href="vote.asp?CurPage=8&id=3488">8</a>
  185. 35.页内跳转
  186. <ahref="#1">1</a>
  187. <a href="#2">2</a>
  188. <ahref="#3">3</a>
  189. <a href="#4">4</a>
  190. <ahref="#5">5</a>
  191. <a href="#6">6</a>
  192. <ahref="#7">7</a>
  193. <a name="1">dfdf</a>
  194. <aname="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><formname=form1>
  211. <INPUTTYPE="button"NAME="aa "value=cindyonclick=haha()>
  212. <INPUT TYPE="button"NAME="bb "value=guoguo>
  213. <INPUTTYPE="button"NAME="bb "value=guoguo>
  214. 39.文字移动
  215. <marquee scrollamount=3onmouseover=this.stop();onmouseout=this.start();>
  216. 40.双击网页自动跑
  217. <SCRIPTLANGUAGE="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. <INPUTTYPE="button"onclick=window.history.back()value=back>
  239. 42.前进
  240. <INPUT TYPE="button"onclick=window.history.forward()value=forward>
  241. 43.刷新
  242. <INPUTTYPE="button"onclick=document.location.reload()value=reload>
  243. 44.转向指定网页
  244. document.location="http://ww"或者document.location.assign("http://guoguo.com")
  245. 45.在网页上显示实时时间
  246. <SCRIPTLANGUAGE="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. <divid=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')"><imgalt=帮助 border=0src="http://bjpic.163.net/images/mail/button-help.gif"></a>
原创粉丝点击