js技巧收集(200多个) (转)

简介:

None.gif 1.文本框焦点问题
None.gifonBlur:当失去输入焦点后产生该事件
None.gifonFocus:当输入获得焦点后,产生该文件
None.gifOnchange:当文字值改变时,产生该事件
None.gifOnselect:当文字加亮后,产生该文件
None.gif
None.gif
< input  type ="text"  value ="郭强"  onfocus ="if(value=='郭强') {value=''}"  onblur ="if 
None.gif(value=='') {value='郭强'}"
> 点击时文字消失,失去焦点时文字再出现
None.gif
None.gif
None.gif2.网页按钮的特殊颜色
None.gif
< input  type =button  name ="Submit1"  value ="郭强"  size =10  class =s02 
None.gif
None.gif
style ="background-color:rgb(235,207,22)" >
None.gif
None.gif3.鼠标移入移出时颜色变化
None.gif
< input  type ="submit"  value ="找吧"  name ="B1"  onMouseOut =this.style.color="blue" 
None.gif
None.gif
onMouseOver =this.style.color="red"   class ="button" >
None.gif
None.gif4.平面按钮
None.gif
< input  type =submit  value =订阅  style ="border:1px solid :#666666; height:17px; width:25pt; font-size:9pt; 
None.gif
None.gifBACKGROUND-COLOR: #E8E8FF; color:#666666"
 name ="submit" >
None.gif
None.gif5.按钮颜色变化
None.gif
< input  type =text  name ="nick"   style ="border:1px solid #666666;  font-size:9pt;  height:17px; 
None.gif
None.gifBACKGROUND-COLOR: #F4F4FF; color:#ff6600"
 size ="15"  maxlength ="16" >
None.gif
None.gif6.平面输入框
None.gif
< input  type ="text"  name ="T1"  size ="20"  style ="border-style: solid; border-width: 1" >
None.gif
None.gif7.使窗口变成指定的大小
ExpandedBlockStart.gif
< script >
ExpandedBlockEnd.gifwindow.resizeTo(
300,283);
None.gif
</ script >
None.gif
None.gif8.使文字上下滚动
None.gif
< marquee  direction =up  scrollamount =1  scrolldelay =100  onmouseover ='this.stop()'  onmouseout ='this.start()' 
None.gif
None.gif
height =60 >
None.gif
<!--  head_scrolltext  -->
None.gif
< tr >
None.gif
< td >
None.gif共和国
None.gif
</ table >          <!--  end head_scrolltext  -->
None.gif
</ marquee >
None.gif
None.gif9.状态栏显示该页状态
None.gif
< base  onmouseover ="window.status='网站建设 http://www.webmake.cn/' ;return true" >
None.gif
None.gif10.可以点击文字实现radio选项的选定
None.gif
< br >
None.gif
&nbsp;&nbsp;&nbsp;&nbsp; < input  type ="radio"  name ="regtype"  value ="A03"  id ="A03" >
None.gif
< label  for ="A03" >  情侣 : 一次注册两个帐户 </ label >   < br >
None.gif
None.gif11.可以在文字域的font写onclick事件
None.gif
None.gif12.打印
</ a > 打印网页
None.gif
< href ='javascript:window.print  ()' >
None.gif
None.gif13.线型输入框
None.gif
< input  type ="text"  name ="key"   size ="12"  value ="关键字"  onFocus =this.select()  onMouseOver =this.focus() 
None.gif
None.gif
class ="line" >
None.gif
None.gif14.显示文档最后修改日期
ExpandedBlockStart.gif
< script  language =javascript >
InBlock.gif
function hi(str)
ExpandedSubBlockStart.gif
{
InBlock.gif document.write(document.lastModified)
InBlock.gif
InBlock.gif alert(
"hi"+str+"!")
ExpandedBlockEnd.gif}

None.gif
</ script >
None.gif
None.gif15.可以在鼠标移到文字上时就触发事件
None.gif
< html >
None.gif
< head >
ExpandedBlockStart.gif
< script  language ="LiveScript" >
InBlock.gif
<!-- Hiding
ExpandedSubBlockStart.gif     
function hello() {
InBlock.gif       alert(
"哈罗!");
ExpandedBlockEnd.gif     }

None.gif
</ script >
None.gif
</ head >
None.gif
< body >
None.gif
< href =""  onMouseOver ="hello()" > link </ a >
None.gif
</ body >
None.gif
</ html >
None.gif
None.gif16.可以根据网页上的选项来确定页面颜色
None.gif
< HTML >
None.gif
< HEAD >
None.gif 
< TITLE > background.html </ TITLE >
None.gif
</ HEAD >
ExpandedBlockStart.gif
< SCRIPT >
InBlock.gif
<!--
InBlock.gif
ExpandedSubBlockStart.gif
function bgChange(selObj) {
InBlock.gif newColor 
= selObj.options[selObj.selectedIndex].text;
InBlock.gif document.bgColor 
= newColor;
InBlock.gif selObj.selectedIndex 
= -1;
ExpandedSubBlockEnd.gif }

InBlock.gif
ExpandedBlockEnd.gif
//-->
None.gif
</ SCRIPT >
None.gif
< BODY  STYLE ="font-family:Arial" >
None.gif
< B > Changing Background Colors </ B >
None.gif
< BR >
None.gif 
< FORM >
None.gif  
< SELECT  SIZE ="8"  onChange ="bgChange(this);" >
None.gif  
< OPTION > Red
None.gif  
< OPTION > Orange
None.gif  
< OPTION > Yellow
None.gif  
< OPTION > Green
None.gif  
< OPTION > Blue
None.gif  
< OPTION > Indigo
None.gif  
< OPTION > Violet
None.gif  
< OPTION > White
None.gif 
< OPTION > pink
None.gif  
</ SELECT >
None.gif 
</ FORM >
None.gif
</ BODY >
None.gif
</ HTML >
None.gif
None.gif17.将按钮的特征改变
ExpandedBlockStart.gif
< style  type ="text/css" >
InBlock.gif<!--
ExpandedSubBlockStart.gif.style1 
{ font-size: 12px; background: #CCCCFF; border-width: thin thin thin thin; border-color: #CCCCFF 
InBlock.gif
ExpandedSubBlockEnd.gif#CCCCCC #CCCCCC #CCCCFF
}

ExpandedSubBlockStart.gif.style2 
{ font-size: 12px; font-weight: bold; background: #CCFFCC; border-width: thin medium medium thin; 
InBlock.gif
ExpandedSubBlockEnd.gifborder-color
: #CCFF99 #999999 #999999 #CCFF99}

ExpandedBlockEnd.gif-->
None.gif
</ style >  
None.gif  本例按钮的代码如下:
None.gif
< input  type ="submit"  name ="Submit"  value ="提 交"  onmouseover ="this.className='style2'"  
None.gif
None.gifonmouseout
="this.className='style1'"  class ="style1" >  
None.gif
None.gif18.改变按钮的图片.
ExpandedBlockStart.gif
< style  type ="text/css" >
InBlock.gif<!--
ExpandedSubBlockStart.gif.style3 
{ font-size: 12px; background: url(image/buttonbg1.gif); border: 0px; width: 60px; height: 22px}
ExpandedSubBlockStart.gif.style4 
{ font-size: 12px; font-weight: bold; background: url(image/buttonbg2.gif); border: 0px 0; width: 
InBlock.gif
ExpandedSubBlockEnd.gif60px
; height: 22px}

ExpandedBlockEnd.gif-->
None.gif
</ style >  
None.gif  本例的按钮代码如下: 
None.gif
< input  type ="submit"  name ="Submit2"  value ="提 交"  onmouseover ="this.className='style4'"  
None.gif
None.gifonmouseout
="this.className='style3'"  class ="style3" >
None.gif
None.gif19.打印页面
None.gif
< div  align ="center" >< class =content  href ="javascript:doPrint();" > 打印本稿 </ a ></ div >
None.gif
None.gif20.可以直接写html语言
None.gifdocument.write("");
None.gif
None.gif21.改变下拉框的颜色
None.gif
< select  name ="classid"  
None.gif
None.gifonChange
="changelocation(document.myform.classid.options[document.myform.classid.selectedIndex].value)"  
None.gif
None.gifsize
="1"  style ="color:#008080;font-size: 9pt" >  
None.gif
None.gif22.转至目标URL
None.gifwindow.location="http://guoguo"
None.gif
None.gif23.传递该object的form
None.gifUpdateSN('guoqiang99267',this.form) 
None.giffunction UpdateSN(strValue,strForm)
None.gif{
None.gif  strForm.SignInName.value = strValue;
None.gif  return false;
None.gif}
None.gif
None.gif24.文字标签
None.gif
< label  for ="AltName4" >< input  name ="AltName"  type ="RADIO"  tabindex ="931"   id ="AltName4"  
None.gif
None.gif
> guoqiang99859 </ label >
None.gif
None.gif25.layer2为组件的ID,可以控制组件是否可见
None.gifdocument.all.item('Layer2').style.display = "block";
None.gifdocument.all.item('Layer2').style.display = "none";//
None.gif
None.gif26.将页面加入favorite中
ExpandedBlockStart.gif
< script  language =javascript >  
InBlock.gif
<!-- 
ExpandedSubBlockStart.gif
function Addme()
InBlock.gifurl 
= "http://your.site.address"//你自己的主页地址 
InBlock.gif
title = "Your Site Name"//你自己的主页名称 
InBlock.gif
window.external.AddFavorite(url,title); 
ExpandedBlockEnd.gif
--> 

None.gif </ script > // 
None.gif
None.gif27.过10秒自动关闭页面
None.gif
<  script  language ="JavaScript"   >
None.giffunction closeit() {
None.gifsetTimeout("self.close()",10000)
None.gif}
None.gif
<  /script  >
None.gif
None.gif28.可以比较字符的大小
None.gifchar=post.charAt(i);
None.gifif(!('0'
< =char &&char< ='9'))
None.gif
None.gif
29.将字符转化为数字
None.gifmonth 
= parseInt(char)
None.gif
None.gif
30.点击value非空的选项时转向指定连接
None.gif <select onchange
='if(this.value!="")window.open(this.value)'  class ="textinput" >
None.gif    
< option  selected > 主办单位 </ option >
None.gif    
< option > ----------------- </ option >
None.gif    
< option  value ="http://www.bjd.com.cn/" > 北京日报 </ option >
None.gif    
< option  value ="http://www.ben.com.cn/" > 北京晚报 </ option >
None.gif
</ select >
None.gif
None.gif31.改变背景颜色
None.gif
< td  width =*  class =dp  bgColor =#FAFBFC  onmouseover ="this.bgColor='#FFFFFF';"  
None.gif
None.gifonmouseout
="this.bgColor='#FAFBFC';" >
None.gif
None.gif32.改变文字输入框的背景颜色
ExpandedBlockStart.gif
< style >
ExpandedSubBlockStart.gif.input2 
{background-image: url('../images/inputbg.gif');   font-size: 12px; background-color: 
InBlock.gif
ExpandedBlockEnd.gif#D0DABB
;border-top-width:1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px}

None.gif
</ style >
None.gif
< input  name =content  type =text  size ="47"  class ="input2"  maxlength ="50" >
None.gif
None.gif33.改变水平线的特征
None.gif
< hr  size ="0"  noshade color ="#C0C0C0" >
None.gif
None.gif34.传递参数的方式
None.gif
< href ="vote.asp?CurPage=8&id=3488" > 8 </ a >
None.gif
None.gif35.页内跳转
None.gif
< href ="#1" > 1 </ a >
None.gif
< href ="#2" > 2 </ a >
None.gif
< href ="#3" > 3 </ a >
None.gif
< href ="#4" > 4 </ a >
None.gif
< href ="#5" > 5 </ a >
None.gif
< href ="#6" > 6 </ a >
None.gif
< href ="#7" > 7 </ a >
None.gif
< name ="1" > dfdf </ a >
None.gif
< name ="2" > dfdf </ a > //
None.gif
None.gif36.两个按键一起按下
None.gifif(event.ctrlKey && window.event.keyCode==13)//
None.gif
None.gif37.刷新页面
None.gifjavascript:this.location.reload()//
None.gif
None.gif38.将网页的按钮使能
ExpandedBlockStart.gif
< SCRIPT  LANGUAGE ="JavaScript" >
InBlock.gif
function haha()
ExpandedSubBlockStart.gif
{
InBlock.gif 
for(var i=0;i<document.form1.elements.length;i++)
ExpandedSubBlockStart.gif 
{
InBlock.gif  
if(document.form1.elements[i].name.indexOf("bb")!=-1)
InBlock.gif   document.form1.elements[i].disabled
=!document.form1.elements[i].disabled;
ExpandedSubBlockEnd.gif }

ExpandedBlockEnd.gif}

None.gif
</ SCRIPT >
None.gif
< BODY >< form  name =form1 >
None.gif
< INPUT  TYPE ="button"  NAME ="aa "   value =cindy  onclick =haha() >
None.gif
< INPUT  TYPE ="button"  NAME ="bb "  value =guoguo >
None.gif
< INPUT  TYPE ="button"  NAME ="bb "  value =guoguo >
None.gif
None.gif39.文字移动
None.gif
< marquee  scrollamount =3  onmouseover =this.stop();  onmouseout =this.start(); >
None.gif
None.gif40.双击网页自动跑
ExpandedBlockStart.gif
< SCRIPT  LANGUAGE ="JavaScript" >
InBlock.gif
var currentpos,timer; 
InBlock.gif
function initialize() 
ExpandedSubBlockStart.gif

InBlock.gif timer
=setInterval("scrollwindow()",1);
ExpandedSubBlockEnd.gif}
 
InBlock.gif
function sc()
ExpandedSubBlockStart.gif
{
InBlock.gif clearInterval(timer);
ExpandedSubBlockEnd.gif}

InBlock.gif
function scrollwindow() 
ExpandedSubBlockStart.gif
{
InBlock.gif currentpos
=document.body.scrollTop;
InBlock.gif window.scroll(
0,++currentpos);
InBlock.gif 
if (currentpos != document.body.scrollTop) 
InBlock.gif  sc();
ExpandedSubBlockEnd.gif}
 
InBlock.gifdocument.onmousedown
=sc
ExpandedBlockEnd.gifdocument.ondblclick
=initialize
None.gif
</ SCRIPT > //
None.gif
None.gif41.后退
None.gif
< INPUT  TYPE ="button"  onclick =window.history.back()  value =back >
None.gif
None.gif42.前进
None.gif
< INPUT  TYPE ="button"  onclick =window.history.forward()  value =forward >
None.gif
None.gif43.刷新
None.gif
< INPUT  TYPE ="button"  onclick =document.location.reload()  value =reload >
None.gif
None.gif44.转向指定网页
None.gifdocument.location="http://ww"或者document.location.assign("http://guoguo.com")
None.gif
None.gif45.在网页上显示实时时间
ExpandedBlockStart.gif
< SCRIPT  LANGUAGE ="JavaScript" >
InBlock.gif
var clock_id;
InBlock.gifwindow.onload
=function()
ExpandedSubBlockStart.gif
{
InBlock.gif clock_id
=setInterval("document.form1.txtclock.value=(new Date);",1000)
ExpandedBlockEnd.gif}

None.gif
</ SCRIPT > //
None.gif
None.gif46.可以下载文件 
None.gifdocument.location.href="目标文件"//
None.gif
None.gif47.连接数据库
None.gifimport java.sql.*;
None.gifString myDBDriver="sun.jdbc.odbc.JdbcOdbcDriver";
None.gifClass.forName(myDBDriver);
None.gifConnection conn=DriverManager.getConnection("jdbc:odbc:firm","username","password");
None.gifStatement stmt=conn.createStatement();
None.gifResultSet rs=stmt.executeQuery(sql);
None.gifrs.getString("column1");//
None.gif
None.gif48.可以直接在页面“div”内写下所需内容
None.gif
< INPUT  TYPE ="button"  onclick ="a1.innerHTML='<font color=red>*</font>'" >
None.gif
< div  id =a1 ></ div > //
None.gif
None.gif49.可以改变页面上的连接的格式,使其为双线
ExpandedBlockStart.gif
< style >
ExpandedSubBlockStart.gifA:link 
{text-decoration: none; color:#0000FF; font-family: 宋体}
ExpandedSubBlockStart.gifA:visited 
{text-decoration: none; color: #0000FF; font-family: 宋体}
ExpandedSubBlockStart.gifA:hover 
{text-decoration: underline overline; color: FF0000}
None.gif
</ style >
None.gif
ExpandedBlockStart.gif
< style >
ExpandedSubBlockStart.gifA:link 
{text-decoration: none; color:#0000FF; font-family: 宋体}
ExpandedSubBlockStart.gifA:visited 
{text-decoration: none; color: #0000FF; font-family: 宋体}
ExpandedSubBlockStart.gifA:hover 
{text-decoration: underline overline line-through; color: FF0000}
ExpandedSubBlockStart.gifTH
{FONT-SIZE: 9pt}
ExpandedSubBlockStart.gifTD
{FONT-SIZE: 9pt}
ExpandedSubBlockStart.gifbody 
{SCROLLBAR-FACE-COLOR: #A9D46D; SCROLLBAR-HIGHLIGHT-COLOR: #e7e7e7;SCROLLBAR-SHADOW-COLOR:#e7e7e7; 
InBlock.gif
InBlock.gifSCROLLBAR-3DLIGHT-COLOR
: #000000; LINE-HEIGHT: 15pt; SCROLLBAR-ARROW-COLOR: #ffffff; 
InBlock.gif
ExpandedSubBlockEnd.gifSCROLLBAR-TRACK-COLOR
: #e7e7e7;}

InBlock.gif
ExpandedSubBlockStart.gifINPUT
{BORDER-TOP-WIDTH: 1px; PADDING-RIGHT: 1px; PADDING-LEFT: 1px; BORDER-LEFT-WIDTH: 1px; FONT-SIZE: 
InBlock.gif
InBlock.gif9pt
; BORDER-LEFT-COLOR: #cccccc; 
InBlock.gifBORDER-BOTTOM-WIDTH
: 1px; BORDER-BOTTOM-COLOR: #cccccc; PADDING-BOTTOM: 1px; BORDER-TOP-COLOR: #cccccc; 
InBlock.gif
ExpandedSubBlockEnd.gifPADDING-TOP
: 1px; HEIGHT: 18px; BORDER-RIGHT-WIDTH: 1px; BORDER-RIGHT-COLOR: #cccccc}

ExpandedSubBlockStart.gifDIV,form ,OPTION,P,TD,BR
{FONT-FAMILY: 宋体; FONT-SIZE: 9pt} 
ExpandedSubBlockStart.giftextarea, select 
{border-width: 1; border-color: #000000; background-color: #efefef; font-family: 宋体; 
InBlock.gif
ExpandedSubBlockEnd.giffont-size
: 9pt; font-style: bold;}

ExpandedSubBlockStart.gif.text 
{ font-family: "宋体"; font-size: 9pt; color: #003300; border: #006600 solid; border-width: 1px 1px 
InBlock.gif
ExpandedBlockEnd.gif1px 1px
}

None.gif
</ style > 完整的css
None.gif
None.gif
None.gif50.新建frame
None.gif
<
None.gif
None.gif
href ="javascript:newframe('http://www.163.net/help/a_little/index.html','http://www.163.net/help/a_little
None.gif
None.gif/a_13.html')"
>< img  alt =帮助  border =0  src ="http://bjpic.163.net/images/mail/button-help.gif" ></ a >
None.gif
None.gif51.向文件中写内容
ExpandedBlockStart.gif
<% @ page import="java.io.*"  %>
ExpandedBlockStart.gif
<%
InBlock.gif 
String str = "print me";
InBlock.gif 
//always give the path from root. This way it almost always works.
InBlock.gif 
String nameOfTextFile = "/usr/anil/imp.txt";
InBlock.gif try
InBlock.gif { 
InBlock.gif  PrintWriter pw 
= new PrintWriter(new FileOutputStream(nameOfTextFile));
InBlock.gif  pw.println(str);
InBlock.gif  
//clean up
InBlock.gif  pw.close();
InBlock.gif }
InBlock.gif catch(IOException e)
InBlock.gif {
InBlock.gif  out.println(e.getMessage());
ExpandedBlockEnd.gif }
None.gif
%>
None.gif
None.gif52.先读文件再写文件
ExpandedBlockStart.gif
<% @ page language = "java"  %>
ExpandedBlockStart.gif
<% @ page contentType = "text/html; charSet=gb2312"  %>
ExpandedBlockStart.gif
<% @ page import ="java.util.*"  %>
ExpandedBlockStart.gif
<% @ page import ="java.lang.*"  %>
ExpandedBlockStart.gif
<% @ page import ="javax.servlet.*"  %>
ExpandedBlockStart.gif
<% @ page import ="javax.servlet.jsp.*"  %>
ExpandedBlockStart.gif
<% @ page import ="javax.servlet.http.*"  %>
ExpandedBlockStart.gif
<% @ page import="java.io.*"  %>
None.giferyrytry
ExpandedBlockStart.gif
<%
InBlock.gif 
int count=0;
InBlock.gif FileInputStream fi 
=new FileInputStream ("count.txt");
InBlock.gif ObjectInputStream si
= new ObjectInputStream (fi);
InBlock.gif count 
=si.readInt();
InBlock.gif count
++;
InBlock.gif out.print(count);
InBlock.gif si.close();
InBlock.gif
InBlock.gif FileOutputStream fo 
=new FileOutputStream ("count.txt");
InBlock.gif ObjectOutputStream so
= new ObjectOutputStream (fo);
InBlock.gif so.writeInt(count);
ExpandedBlockEnd.gif so.close();
None.gif
%>
None.gif
None.gif53.直线型输入框
None.gif
< INPUT  name =Password  size =10  type =password  style ="border-left-width: 0; border-right-width: 0; 
None.gif
None.gifborder-top-width: 0; border-bottom-style: solid; border-bottom-width: 1; background-color: #9CEB9C"
>
None.gif
None.gif54.可以将背景改为按钮性状,通过改变css改变属性
None.gif
< td  width ="65"  align ="center"  bgcolor ="#E0E0E0"  onmouseover =this.className='mouseoverbt'; 
None.gif
None.gif
onmouseout =this.className='mouseout'; >< href ="tm.asp?classid=76" >< font 
None.gif
None.gif
color ="#000000" > 录音笔 </ font ></ a ></ td >
ExpandedBlockStart.gif
< style >
InBlock.gif.mouseoverbt 
ExpandedSubBlockStart.gif
{
InBlock.gif background-image
: url(http://www.yongle.com.cn/img/btbgw64h20y.gif);
InBlock.gif background-repeat
: no-repeat;
ExpandedSubBlockEnd.gif
}

InBlock.gif.mouseout 
ExpandedSubBlockStart.gif
{
InBlock.gif background-color
: #E0E0E0;
ExpandedBlockEnd.gif
}

None.gif
</ style >
None.gif
None.gif55.同时按下CTRL和Q键
None.gifdocument.onkeydown=function()
None.gif{
None.gifif(event.ctrlKey&
&event .keyCode==81)
None.gif{alert(1)}
None.gif}//
None.gif
None.gif56.以下是一个完整的显示hint的代码,其思想是当鼠标停留是将div中的内容显示在鼠标出,当鼠标移出后在将该div隐
None.gif
None.gif藏掉
None.gif---------------------------------------------------------------------------------------------------------
None.gif
None.gif------------
None.gif
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
None.gif
< HTML >
ExpandedBlockStart.gif
< style >
ExpandedSubBlockStart.gif#hint
{
InBlock.gif width
:198px;
InBlock.gif border
:1px solid #000000;
InBlock.gif background
:#99ff33;
InBlock.gif position
:absolute;
InBlock.gif z-index
:9;
InBlock.gif padding
:6px;
InBlock.gif line-height
:17px;
InBlock.gif text-align
:left;
InBlock.gif top
: 1520px;
ExpandedBlockEnd.gif
}

None.gif
</ style >
ExpandedBlockStart.gif
< SCRIPT  LANGUAGE ="JavaScript" >
InBlock.gif
<!--
InBlock.gif
function showme()
ExpandedSubBlockStart.gif
{
InBlock.gif 
var oSon=window.document.getElementById("hint");
InBlock.gif 
if (oSon==nullreturn;
InBlock.gif 
with (oSon) 
ExpandedSubBlockStart.gif 
{
InBlock.gif  innerText
=guoguo.value;
InBlock.gif  style.display
="block";
InBlock.gif  style.pixelLeft
=window.event.clientX+window.document.body.scrollLeft+6;
InBlock.gif  style.pixelTop
=window.event.clientY+window.document.body.scrollTop+9;
ExpandedSubBlockEnd.gif }

ExpandedSubBlockEnd.gif}

InBlock.gif
function hidme()
ExpandedSubBlockStart.gif
{
InBlock.gif 
var oSon=window.document.getElementById("hint");
InBlock.gif 
if (oSon==nullreturn;
InBlock.gif oSon.style.display
="none";
ExpandedSubBlockEnd.gif}

ExpandedBlockEnd.gif
//-->
None.gif
</ SCRIPT >
None.gif
< BODY >
None.gif
< text  id =guoguo  value =ga >
None.gif
< href =#  onmouseover =showme()  onmouseout =hidme()  onmousemove =showme()  son =hint > dfdfd </ a >
None.gif
< div  id =hint  style ="display:none" ></ div >
None.gif
</ BODY >
None.gif
</ HTML >
None.gif---------------------------------------------------------------------------------------------------------
None.gif
None.gif------------
None.gif
None.gif57.弹出窗口
None.gif方法一:
< body  onload ="openwen()" >  浏览器读页面时弹出窗口; 
None.gif方法二:
< body  onunload ="openwen()" >  浏览器离开页面时弹出窗口; 
None.gif方法三:用一个连接调用:
< href ="#"  onclick ="openwin()" > 打开一个窗口 </ a >  
None.gif注意:使用的"#"是虚连接。 
None.gif方法四:用一个按钮调用:
< input  type ="button"  onclick ="openwin()"  value ="打开窗口" >  何时装载script
None.gif
None.gif
None.gif58.动态改变字体的大小
None.giffunction doZoom(size)
None.gif{
None.gif   document.getElementById('zoom').style.fontSize=size+'px'
None.gif}
None.gif
None.giffunction aa()
None.gif{
None.gif   var newWin=window.open(url);
None.gif   newWin.document.form1.text1.value=value1;
None.gif}改变弹出窗口上域的属性
None.gifopener.document.form2.text2.value=value2;改变父窗口的域的值
None.gif
None.gif59.判断是何种浏览器
None.gifvar name = navigator.appName;
None.gifif (name == "Microsoft Internet Explorer")
None.gif alert("IE");
None.gifelse if (name == "Netscape")
None.gif alert("NS");//
None.gif
None.gif60.vbsscript确定框
ExpandedBlockStart.gif
< script  language ="VBScript" >
InBlock.gif
<!--
InBlock.gif
MsgBox "确定删除吗?"4 
ExpandedBlockEnd.gif
//-->
None.gif
</ script > //
None.gif
None.gif61.复制内容到剪切板
None.giffunction JM_cc(bb)
None.gif{
None.gif    var ob=eval("document.form1."+bb);
None.gif    ob.select();
None.gif    js=ob.createTextRange();
None.gif    js.execCommand("Copy");
None.gif}//
None.gif
None.gif62.java中建立数据库连接取数据
None.gifpublic void init()
None.gif{
None.gif String url="jdbc:odbc:javadata";
None.gif try
None.gif {
None.gif  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
None.gif  Connection con=DriverManager.getConnection(url,"sa","");//mssql database user SA and password
None.gif  DatabaseMetaData dma=con.getMetaData();
None.gif  System.out.println("Connect to"+dma.getURL());
None.gif  System.out.println(";Driver "+dma.getDriverName());
None.gif  System.out.println(";Version "+dma.getDriverVersion());
None.gif  System.out.println("");
None.gif  Statement stmt=con.createStatement();
None.gif  ResultSet rs=stmt.executeQuery("select * from company.dbo.TB_NAME where number=1");//Sql 
None.gif  rs.next();
None.gif  String dispresult=rs.getString("name");
None.gif  System.out.println(dispresult);// Instead,you can display it in Paint() or use AWT etc.
None.gif  rs.close();
None.gif  stmt.close();
None.gif  con.close();
None.gif }
None.gif catch(SQLException ex)
None.gif {
None.gif  System.out.println("!!!SQL Exception !!!");
None.gif  while(ex!=null)
None.gif  {
None.gif   System.out.println("SQLState:"+ex.getSQLState());
None.gif   System.out.println("Message:"+ex.getMessage());
None.gif   System.out.println("Vendor:"+ex.getErrorCode());
None.gif   ex=ex.getNextException();
None.gif   System.out.println("");
None.gif  }
None.gif
None.gif }
None.gif catch(java.lang.Exception ex)
None.gif {
None.gif  ex.printStackTrace();
None.gif }
None.gif}//
None.gif
None.gif
None.gif63.最小化窗口
None.gifwindow.blur()//
None.gif
None.gif
None.gif64.文档的路径
None.gifdocument.URL//
None.gif
None.gif65.定时执行某段程序
None.gifsetTimeout("change_color()",600);
None.gif
None.gif66.设置为主页
None.giffunction makeHome(){
None.gif  netscape.security.PrivilegeManager.enablePrivilege("UniversalPreferencesWrite");
None.gif  navigator.preference("browser.startup.homepage", location.href);
None.gif}//
None.gif
None.gif67.设置为收藏
None.giffunction addFav(){
None.gif  if(ie)
None.gif    window.external.AddFavorite(location.href,'WWW.OGRISH.COM : GROTESQUE MOVIES AND PICTURES');
None.gif  if(ns)
None.gif    alert("Thanks for the bookmark!\n\nNetscape users click OK then press CTRL-D");
None.gif}//
None.gif
None.gif68.判断cookie是否可用
None.gifnavigator.cookieEnabled;//
None.gif
None.gif69.显示有模式的有页面的弹出窗口
None.giffunction setbgcolor_onclick()
None.gif{
None.gif var color = showModalDialog("/mailpage/compose/colorsel.html",0,"help=0");
None.gif if (color != null)
None.gif {
None.gif  document.compose.bgcolor.value = color;
None.gif }
None.gif}//
None.gif
None.gif
None.gif70.截取小数点后两位
None.gifvar a=3454545.4454545;
None.gifalert(a.toFixed(2));//
None.gif
None.gif
None.gif71.禁止选择页面上的文字来拷贝
ExpandedBlockStart.gif
< script >
ExpandedSubBlockStart.gif
function noEffect() {
ExpandedSubBlockStart.gif  
with (event) {
InBlock.gif    returnValue 
= false;
InBlock.gif    cancelBubble 
= true;
ExpandedSubBlockEnd.gif  }

InBlock.gif  
return;
ExpandedBlockEnd.gif}

None.gif
</ script >
None.gif
< body  onselectstart ="noEffect()"  oncontextmenu ="noEffect()" > //
None.gif
None.gif72.屏蔽右键菜单
None.gifoncontextmenu="event.returnValue = false"//
None.gif
None.gif73.事件禁止起泡
None.gifevent.cancelBubble = true//
None.gif
None.gif74.禁止在输入框打开输入法
None.gif
< input  style ="ime-mode: disabled" > //
None.gif
None.gif75.屏蔽汉字和空格
None.gif
< input  name ="txt" >< input  type ="submit"  onClick ="alert(!/[^ -}]|\s/.test(txt.value))" > //
None.gif
None.gif76.用javascript判断文件是否存在
None.giffunction Exists(filespec)
None.gif{
None.gif if (filespec)
None.gif {
None.gif  var fso;
None.gif  fso = new ActiveXObject("Scripting.FileSystemObject");
None.gif  alert(fso.FileExists(filespec));
None.gif }
None.gif}
None.gif选择图片 
< input  type =file  name =f1 >< p >
None.gif
< input  type ="submit"  onClick ="Exists(f1.value)" > //
None.gif
None.gif77.获得当前的文本框选中的文字
None.gif
< input  onmouseup ="alert(document.selection.createRange().text)"  value =123 > //
None.gif
None.gif78.跳转至目标页面,同时不可返回
None.gif
< href ="javascript:location.replace('http://www.sohu.com/')" > sohu.com </ a > //
None.gif
None.gif 
None.gif79.获得当前的行是表格的第几行
ExpandedBlockStart.gif
< script >
InBlock.gif
function getrow(obj)
ExpandedSubBlockStart.gif
{
ExpandedSubBlockStart.gif   
if(event.srcElement.tagName=="TD"){
InBlock.gif   curRow
=event.srcElement.parentElement;
InBlock.gif   alert(
"这是第"+(curRow.rowIndex+1)+"");
InBlock.gif
ExpandedSubBlockEnd.gif   }

ExpandedBlockEnd.gif}

None.gif
</ script >
None.gif
None.gif
< table  border ="1"  width ="100%"  onclick =getrow(this) >
None.gif  
< tr >
None.gif    
< td  width ="20%" >   </ td >
None.gif    
< td  width ="20%" >   </ td >
None.gif    
< td  width ="20%" >   </ td >
None.gif    
< td  width ="20%" >   </ td >
None.gif    
< td  width ="20%" >   </ td >
None.gif  
</ tr >
None.gif  
< tr >
None.gif    
< td  width ="20%" >   </ td >
None.gif    
< td  width ="20%" >   </ td >
None.gif    
< td  width ="20%" >   </ td >
None.gif    
< td  width ="20%" >   </ td >
None.gif    
< td  width ="20%" >   </ td >
None.gif  
</ tr >
None.gif
</ table > //
None.gif
None.gif80.删除表格某行,xx表示某行,下标从0开始计算
None.gifdocument.all.myTable.deleteRow(xx)//
None.gif
None.gif81.动态的向表格中添加行
None.gif
< table  id ="t1"  border ="1" >
None.gif
</ table >
ExpandedBlockStart.gif
< script  language ="JavaScript" >
InBlock.gif
function add()
ExpandedSubBlockStart.gif
{
InBlock.gif   t1.insertRow().insertCell().innerHTML 
= '<input name="test'+t1.rows.length+'">';
ExpandedSubBlockEnd.gif}
//
InBlock.gif

InBlock.gif 
InBlock.gif
InBlock.gif
82.event.x,event.clientX,event.offsetX区别:
InBlock.gifx:设置或者是得到鼠标相对于目标事件的父元素的外边界在x坐标上的位置。 clientX:相对于客户区域的x坐标位置,不
InBlock.gif
InBlock.gif包括滚动条,就是正文区域。 offsetx:设置或者是得到鼠标相对于目标事件的父元素的内边界在x坐标上的位置。 
InBlock.gifscreenX:相对于用户屏幕。 
InBlock.gif
InBlock.gif 
InBlock.gif
83.显示是鼠标按钮的哪个
InBlock.gif
<body onMouseDown="alert(event.button)">点Mouse看看//
InBlock.gif

InBlock.gif
84.打开C盘
InBlock.gif
<form action="file:///c|/"><input type="submit" value="c:\ drive"></form>//
InBlock.gif
 
InBlock.gif
85.当前屏幕的分辨率
InBlock.gifscreen.width、screen.height
//
InBlock.gif

InBlock.gif
86.设置表格中的内容
InBlock.giftbl.rows[
0].cells[1].innerText=document.form.text1.value;//
InBlock.gif

InBlock.gif 
InBlock.gif
87.本地快捷键
InBlock.gif
<p><a href="file:///::{208D2C60-3AEA-1069-A2D7-08002B30309D}" target="_blank">网上邻居</a></p>
InBlock.gif
<p><a href="file:///::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\d:\web" target="_blank">我的电脑</a></p>
InBlock.gif
<p><a href="file:///::{450D8FBA-AD25-11D0-98A8-0800361B1103}" target="_blank">我的文档</a></p>
InBlock.gif
<p><a href="file:///::{645FF040-5081-101B-9F08-00AA002F954E}" target="_blank">回收站</a></p>
InBlock.gif
<p><a href="file:///::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\::{21EC2020-3AEA-1069-A2DD-08002B30309D}" 
InBlock.gif
InBlock.giftarget
="_blank">控制面板</a></p>
InBlock.gif
<p><a href="file:///::{7007ACC7-3202-11D1-AAD2-00805FC1270E}">拨号网络</a>(windows 2000)</p>
InBlock.gif
InBlock.gif  
InBlock.gif
88.IE菜单
InBlock.gif
<button onclick="min.Click()"><font face="webdings">0</font></button>//改变按钮上的图片
InBlock.gif
<input type=button  onclick="document.execCommand('CreateLink','true','true')"> //创建新连接
InBlock.gif
<input type=button  onclick="document.execCommand('print','true','true')"> //打印
InBlock.gif
<input type=button  onclick="document.execCommand('saveas','true','网站制作.htm')">//另存为htm
InBlock.gif
<input type=button  onclick="document.execCommand('saveas','true','网站制作.txt')">//另存为txt
InBlock.gif
document.execCommand("SaveAs")//保存为
InBlock.gif
document.execCommand('undo')//撤销上一次操作
InBlock.gif

InBlock.gif
89.web对话框
InBlock.gif
<SCRIPT>
ExpandedSubBlockStart.gif
var contents='<style>body,td{font:menu}img{cursor:hand}</style>';
InBlock.gifcontents
+='<title>你要关闭我吗</title>';
InBlock.gifcontents
+='<body bgcolor=menu>';
InBlock.gifcontents
+='<table width=100% height=100% border=0>';
InBlock.gifcontents
+='<tr><td align=center>';
InBlock.gifcontents
+='你要关闭我吗?<br>';
InBlock.gifcontents
+='<img src=dark.gif onclick=self.close() alt="dot.gif关闭">';
InBlock.gifcontents
+='<img src=jet.gif onclick=self.close() alt="全是关闭">';
InBlock.gifcontents
+='</td></tr></table>';
InBlock.gifshowModalDialog(
"about:"+contents+"","","dialogHeight:50px;dialogWidth:250px;help:no;status:no")
ExpandedBlockEnd.gifdocument.write(contents);
None.gif
</ SCRIPT > //
None.gif
None.gif90.取第x,y的值
None.gif
< button  onclick ="t1.rows[x].cells[y].innerText='guoguo'" ></ button > //
None.gif
None.gif91.向新打开的网页上写内容
None.gifnewwin=window.open('about:blank','','top=10');
None.gifnewwin.document.write('');//
None.gif
None.gif93.返回
None.gifjavascript:history.go(-2);//
None.gif
None.gif94.将页面上选中的内容复制到剪贴板
None.gifabcdefg
None.gif
< input  type ='button' 
None.gif
None.gif
onclick ="window.clipboardData.setData('text',document.selection.createRange().text);"  value ='复制页面选中
None.gif
None.gif
的字符' > //
None.gif95.将页面上选中的内容复制到剪贴板
None.gif
< INPUT  TYPE ="text"  NAME ="" > kjhkjhkhkj < INPUT  TYPE ="button"  onclick ="document.execCommand('Copy', 'false', 
None.gif
None.gifnull);"
> ////
None.gif
None.gif96.鼠标移到下拉框时自动全部打开
None.gif
< select  onmouseover ="javascript:this.size=this.length"  onmouseout ="javascript:this.size=1" ></ select > //
None.gif
None.gif97.获得本机的文件
None.gifvar fso = new ActiveXObject("Scripting.FileSystemObject"); 
None.gifvar f1 = fso.GetFile("C:\\bsitcdata\\ejbhome.xml"); 
None.gifalert("File last modified: " + f1.DateLastModified); //
None.gif
None.gif98.判断客户端是否是IE浏览器
None.gif因为 document.all 是 IE 的特有属性,所以通常用这个方法来判断客户端是否是IE浏览器 ,document.all?1:0;
None.gif
None.gif99.创建新的下拉框选项
None.gifnew Option(text,value)这样的函数//
None.gif
None.gif100.在页面上画柱状图
ExpandedBlockStart.gif
< STYLE >
ExpandedSubBlockStart.giftd
{font-size:12px}
ExpandedSubBlockStart.gifbody
{font-size:12px}
ExpandedSubBlockStart.gifv\:*
{behavior:url(#default#VML);} //这里声明了v作为VML公用变量
None.gif
</ STYLE >
ExpandedBlockStart.gif
< SCRIPT  LANGUAGE ="JavaScript" >
InBlock.gifmathstr
=12;
InBlock.gifdocument.write (
"<v:rect fillcolor='red' 
InBlock.gif
InBlock.gifstyle='width:20;color:navy;height:
"+5000/(1000/mathstr)+"'><br>&nbsp;%"+mathstr+"<br>4人<v:Extrusion 
InBlock.gif
ExpandedBlockEnd.gifbackdepth='15pt' on='true'/></v:rect>
")
None.gif
</ SCRIPT >
None.gif
< v:rect  fillcolor ='red'  style ='width:20;color:navy;height:200' >< br > %12 < br > 4人 < v:Extrusion 
None.gif
None.gif
backdepth ='15pt'  on ='true' /></ v:rect >
None.gif
< v:rect  fillcolor ='yellow'  style ='width:20;color:navy;height:100' >< br > %12 < br > 4人 < v:Extrusion 
None.gif
None.gif
backdepth ='15pt'  on ='true' /></ v:rect > //
None.gif
None.gif 
None.gif
None.gif101.饼图
ExpandedBlockStart.gif
< style >
ExpandedSubBlockStart.gifv\:*     
{ behavior: url(#default#VML) }
ExpandedSubBlockStart.gifo\:*     
{ behavior: url(#default#VML) }
ExpandedSubBlockStart.gif.shape    
{ behavior: url(#default#VML) }
None.gif
</ style >
ExpandedBlockStart.gif
< script  language ="javascript" >
InBlock.gif
function show(pie)
ExpandedSubBlockStart.gif
{
InBlock.gifpie.strokecolor
=pie.fillcolor;
InBlock.gifpie.strokeweight
=10;
InBlock.gifdiv1.innerHTML
="<font size=2 color=red> " + pie.id +"</font> <font size=2>" + pie.title + "</font>";
ExpandedSubBlockEnd.gif}

InBlock.gif
function hide(pie)
ExpandedSubBlockStart.gif
{
InBlock.gifpie.strokecolor
="white";
InBlock.gifpie.strokeweight
=1;
InBlock.gifdiv1.innerHTML
="";
ExpandedBlockEnd.gif}

None.gif
</ script >
None.gif
</ head >
None.gif
< body >
None.gif
< v:group  style ='width:  5cm; height: 5cm' coordorigin ='0,0'  coordsize ='250,250' >
None.gif
< v:shape  id ='asp技术'  style ='width:10;height:10;top:10;left:0'  title ='得票数:6  比例:40.00%' 
None.gif
None.gifonmouseover
='javascript:show(this);'  onmouseout ='javascript:hide(this);'  href ='http://www.cnADO.com' 
None.gif
None.gif
CoordSize ='10,10'  strokecolor ='white'  fillcolor ='#ffff33' >< v:path  v ='m  300,200 ae 
None.gif
None.gif300,200,200,150,0,9437184 xe'
/></ v:shape >
None.gif
< v:shape  id ='php'  style ='width:10;height:10;top:10;left:0'  title ='得票数:1  比例:6.67%' 
None.gif
None.gifonmouseover
='javascript:show(this);'  onmouseout ='javascript:hide(this);'  href ='http://www.cnADO.com' 
None.gif
None.gif
CoordSize ='10,10'  strokecolor ='white'  fillcolor ='#ff9933' >< v:path  v ='m  300,200 ae 
None.gif
None.gif300,200,200,150,9437184,1572864 xe'
/></ v:shape >
None.gif
< v:shape  id ='jsp'  style ='width:10;height:10;top:10;left:0'  title ='得票数:2  比例:13.33%' 
None.gif
None.gifonmouseover
='javascript:show(this);'  onmouseout ='javascript:hide(this);'  href ='http://www.cnADO.com' 
None.gif
None.gif
CoordSize ='10,10'  strokecolor ='white'  fillcolor ='#3399ff' >< v:path  v ='m  300,200 ae 
None.gif
None.gif300,200,200,150,11010048,3145728 xe'
/></ v:shape >
None.gif
< v:shape  id ='c#写的.netWEB程序'  style ='width:10;height:10;top:10;left:0'  title ='得票数:3  比例:20.00%' 
None.gif
None.gifonmouseover
='javascript:show(this);'  onmouseout ='javascript:hide(this);'  href ='http://www.cnADO.com' 
None.gif
None.gif
CoordSize ='10,10'  strokecolor ='white'  fillcolor ='#99ff33' >< v:path  v ='m  300,200 ae 
None.gif
None.gif300,200,200,150,14155776,4718592 xe'
/></ v:shape >
None.gif
< v:shape  id ='vb.net写的.netWEB程序'  style ='width:10;height:10;top:10;left:0'  title ='得票数:2  比例:13.33%' 
None.gif
None.gifonmouseover
='javascript:show(this);'  onmouseout ='javascript:hide(this);'  href ='http://www.cnADO.com' 
None.gif
None.gif
CoordSize ='10,10'  strokecolor ='white'  fillcolor ='#ff6600' >< v:path  v ='m  300,200 ae 
None.gif
None.gif300,200,200,150,18874368,3145728 xe'
/></ v:shape >
None.gif
< v:shape  id ='xml技术'  style ='width:10;height:10;top:10;left:0'  title ='得票数:1  比例:6.67%' 
None.gif
None.gifonmouseover
='javascript:show(this);'  onmouseout ='javascript:hide(this);'  href ='http://www.cnADO.com' 
None.gif
None.gif
CoordSize ='10,10'  strokecolor ='white'  fillcolor ='#ff99ff' >< v:path  v ='m  300,200 ae 
None.gif
None.gif300,200,200,150,22020096,1572864 xe'
/></ v:shape >
None.gif
</ v:group >
None.gif
None.gif
< v:group  style ='width:  6cm; height: 6cm' coordorigin ='0,0'  coordsize ='250,250' >
None.gif
< v:rect  style ='height:10;width:15;top:0;left:10'  fillcolor ='#ffff33' />
None.gif
< v:rect  style ='height:28;width:100;top:0;left:30'  stroked ='false' >< v:textbox 
None.gif
None.gif
style ='fontsize:2' > asp技术 </ v:textbox/ ></ v:rect >
None.gif
< v:rect  style ='height:10;width:15;top:30;left:10'  fillcolor ='#ff9933' />
None.gif
< v:rect  style ='height:28;width:100;top:30;left:30'  stroked ='false' >< v:textbox 
None.gif
None.gif
style ='fontsize:2' > php </ v:textbox/ ></ v:rect >
None.gif
< v:rect  style ='height:10;width:15;top:60;left:10'  fillcolor ='#3399ff' />
None.gif
< v:rect  style ='height:28;width:100;top:60;left:30'  stroked ='false' >< v:textbox 
None.gif
None.gif
style ='fontsize:2' > jsp </ v:textbox/ ></ v:rect >
None.gif
< v:rect  style ='height:10;width:15;top:90;left:10'  fillcolor ='#99ff33' />
None.gif
< v:rect  style ='height:28;width:100;top:90;left:30'  stroked ='false' >< v:textbox 
None.gif
None.gif
style ='fontsize:2' > c#写的.netWEB程序 </ v:textbox/ ></ v:rect >
None.gif
< v:rect  style ='height:10;width:15;top:120;left:10'  fillcolor ='#ff6600' />
None.gif
< v:rect  style ='height:28;width:100;top:120;left:30'  stroked ='false' >< v:textbox  style ='fontsize:2' > vb.net
None.gif
None.gif写的.netWEB程序
</ v:textbox/ ></ v:rect >
None.gif
< v:rect  style ='height:10;width:15;top:150;left:10'  fillcolor ='#ff99ff' />
None.gif
< v:rect  style ='height:28;width:100;top:150;left:30'  stroked ='false' >< v:textbox  style ='fontsize:2' > xml技术
None.gif
None.gif
</ v:textbox/ ></ v:rect >
None.gif
</ v:group >
None.gif
None.gif
< div  style ="position: absolute; left: 10; top: 10; width: 760; height:16" >
None.gif 
< table  border ="1"  cellpadding ="2"  cellspacing ="2"  cellpadding ="0"  cellspacing ="0"  
None.gif
None.gifstyle
="border-collapse: collapse"  bordercolor ="#CCCCCC"  width ="100%"  ID ="Table1" >
None.gif  
< tr >
None.gif   
< td  width ="100%"  id =div1 >   </ td >
None.gif  
</ tr >
None.gif 
</ table >
None.gif
</ div > //
None.gif
None.gif102.是一个特殊的容器,想装个网页都行
None.gif
< button >< iframe  src ="http://www.google.com/" ></ iframe ></ button > //button 
None.gif
None.gif103.外部的html代码
None.gifevent.srcElement.outerHTML//
None.gif
None.gif104.标识当前的IE事件的触发器
None.gifevent.srcElement和event.keyCode//
None.gif
None.gif105.事件类型
None.gifevent.type//
None.gif
None.gif106.动态改变类型
ExpandedBlockStart.gif
< style >
ExpandedSubBlockStart.gif.Overnone 
{ border-width:0;background-color:darkblue;cursor:default;color:gold;width:115}
ExpandedSubBlockStart.gif.Outnone   
{border-width:0;background-color:white;cursor:default;width:115}
None.gif
</ style >
None.gif
< input  class =Outnone  onmouseover =this.className='Overnone'  > //
None.gif
None.gif107.页面翻转
None.gif
< html  dir =rtl ></ html > //
None.gif
None.gif108.滚屏
None.gifparent.scroll(x,y);//
None.gif
< body  onload ="s=0"  onDblClick ="s=setInterval('scrollBy(0, 1)',10)"  onClick ="clearInterval(s)" > //
None.gif
None.gif109.改变状态栏
None.gifself.status ="";//
None.gif
None.gif110.改变窗口大小
None.gifwindow.resizeTo(200,300);//
None.gif
None.gif111.改变鼠标样式
None.gifstyle
None.gifBODY{CURSOR: url('mouse.ani');
None.gifSCROLLBAR-BASE-COLOR: #506AA8; 
None.gifSCROLLBAR-ARROW-COLOR: #14213F;
None.gif}//
None.gif
None.gif112.背景透明
None.gif
< input  type ="button"  value ="Button"  style ="background-color: transparent; border: 0;" > //
None.gif
None.gif113.鼠标为等待形状
None.gif
< input  type =button  onclick ="this.style.cursor='wait'" > //
None.gif
None.gif114.调用父窗口的函数
None.gifopener.fucntion1();//
None.gif
None.gif115.body的内部html代码
None.gif
< input  type ="button"  onclick ="alert(code.document.body.innerHTML)"  value ="查看" > //
None.gif
None.gif116.框架中调用父窗口的函数
None.gif
< INPUT  TYPE ='button'  onclick ='parent.test();'  value ='调用parent窗口的函数' > //
None.gif
None.gif117.交换节点
None.gif
< table   width =200   height =200   border >
None.gif
< tr >< td   id =c1 > CELL_1 </ td ></ tr >
None.gif
< tr >< td   id =c2 > CELL_2 </ td ></ tr >
None.gif
</ table >
None.gif
< br >
None.gif
< input   type ="button"   value ="swap  row"   onclick ="c1.swapNode(c2)" > //
None.gif
None.gif118.删除节点
None.gif
< table   width =200   height =200   border >
None.gif
< tr  id =trall >< td   id =c1 > CELL_1 </ td ></ tr >
None.gif
< tr >< td   id =c2 > CELL_2 </ td ></ tr >
None.gif
</ table >
None.gif
< br >
None.gif
< input   type ="button"   value ="swap  row"   onclick ="trall.removeNode(c2)" > //
None.gif
None.gif119.添加节点
None.gifaddNode()//
None.gif
None.gif120.获得事件的父与子标签
None.gifevent.srcElement.children[0]和event.srcElement.parentElement //
None.gif
None.gif 
None.gif121.集中为按钮改变颜色
ExpandedBlockStart.gif
< style >
ExpandedSubBlockStart.gifbutton
{benc:expression(this.onfocus = function(){this.style.backgroundColor='#E5F0FF';})}
None.gif
</ style >
None.gif
< button > New </ button > //
None.gif
None.gif
None.gif122.判断是左键还是右键被按下
None.gif
< body  onmousedown =if(event.button==1)alert("左键");if(event.button==2)alert("右键") > //
None.gif
None.gif123.获得操作系统的名称和浏览器的名称
None.gifdocument.write(navigator.userAgent)//
None.gif
None.gif 
None.gif124.alt/ctrl/shift键按下
None.gifevent.altKey //按下alt键
None.gifevent.ctrlKey //按下ctrl键
None.gifevent.shiftKey //按下shift键
None.gif
None.gif 
None.gif
None.gif125.将当前位置定位为C盘。
None.gif{window.location="c:"}//
None.gif
None.gif126.返回输入框的类型
ExpandedBlockStart.gif
< script >
ExpandedBlockEnd.gifalert(event.srcElement.type);
//
None.gif
</ script >
None.gif
None.gif127.模拟控件的单击事件
None.gif
< INPUT  TYPE ="hidden"  name ="guoguo"  onclick ="haha()" >
ExpandedBlockStart.gif
< SCRIPT  LANGUAGE ="JavaScript" >
InBlock.gif
<!--
InBlock.gif
InBlock.gif
function haha()
ExpandedSubBlockStart.gif
{
InBlock.gif alert();
ExpandedSubBlockEnd.gif}

InBlock.gifguoguo.click();
ExpandedBlockEnd.gif
//-->
None.gif
</ SCRIPT > //
None.gif
None.gif 
None.gif128.取出记录集的列名
None.gifjava.sql.ResultSet rset = com.bsitc.util.DBAssist.getIT().executeQuery(queryStatement, conn);
None.gifjava.sql.ResultSetMetaData metaData = rset.getMetaData();
None.gifint count = metaData.getColumnCount();
None.gifString name = metaData.getColumnName(i);
None.gifString value = rset.getString(i);//
None.gif
None.gif129.格式化数字
None.giffunction format_number(str,digit)
None.gif{
None.gif if(isNaN(str))
None.gif {
None.gif  alert("您传入的值不是数字!");
None.gif  return 0;
None.gif }
None.gif else if(Math.round(digit)!=digit)
None.gif {
None.gif  alert("您输入的小数位数不是整数!");
None.gif  return 0;
None.gif }
None.gif else 
None.gif  return Math.round(parseFloat(str)*Math.pow(10,digit))/Math.pow(10,digit);
None.gif}
None.gif
None.gif130.回车按钮转化为tab按钮
None.gifif(event.keyCode==13) event.keyCode=9; //将
None.gif
None.gif 
None.gif131.滚动条滚动
None.gif
< button  onclick ="text1.scrollTop=text1.scrollHeight" > Scroll </ button >< br >
None.gif
< textarea  id ="text1"  cols =50  rows =10 >
None.gif1
None.gif1
None.gif1
None.gif1
None.gif1
None.gif1
None.gif1
None.gif1
None.gif1
None.gif1
None.gif1
None.gif1
None.gif1
None.gif1
None.gif1
None.gif
</ textarea > //
None.gif
None.gif 
None.gif132.判断是什么对象
None.gifif(typeof(unknown)=="function")return true;
None.gifif(typeof(unknown)!="object")return false;//
None.gif
None.gif 
None.gif133.取消文本框自动完成功能
None.gif
< input  type ="text"  autocomplete ="off" >  //
None.gif
None.gif134.让下拉框自动下拉
None.gif
< select  onmouseover ="javascript:this.size=this.length"  onmouseout ="javascript:this.size=1" >
None.gif
< option  value ="" > 1 </ option >
None.gif
< option  value ="" > 2 </ option >
None.gif
< option  value ="" > 3 </ option >
None.gif
</ select >  //
None.gif
None.gif 
None.gif135.读取XML文件
None.gifvar childrenobj=myselect//document.all.myselect;
None.gif    var oXMLDoc = new ActiveXObject('MSXML');
None.gif    oXMLDoc.url = "mymsg.xml";
None.gif    var oRoot=oXMLDoc.root;
None.gif    if(oRoot.children != null) 
None.gif {
None.gif        for(var i=0;i
< oRoot .children.item(0).children.length;++i)
None.gif  {
None.gif            oItem 
= oRoot.children.item(0).children.item(i);
None.gif            
oOption  = new  Option(oItem.text,oItem.value);
None.gif   childrenobj.add(oOption);
None.gif        }
None.gif    }
None.gif//mymsg.xml文件
None.gif<?xml version
="1.0"  encoding ="gb2312"  ? >
None.gif
< childrenlist >
None.gif
< aa >
None.gif
< child  value ='3301' > 杭州地区 </ child >
None.gif
None.gif
< child  value ='3303' > 温州地区 </ child >
None.gif
None.gif
</ aa >
None.gif
< aa >
None.gif
< child  value ='3310' > 台州地区 </ child >
None.gif
None.gif
< child  value ='3311' > 丽水地区 </ child >
None.gif
</ aa >
None.gif
</ childrenlist > //
None.gif
None.gif 
None.gif136.点击图片,图片停止
None.gif
< href ="javascript:" >< img  src ="http://www.51js.com/images/51js/red_forum.gif"  border ="0" ></ a > //
None.gif
None.gif137.显示本地计算机信息
None.gifvar WshNetwork = new ActiveXObject("WScript.Network");
None.gifalert("Domain = " + WshNetwork.UserDomain);
None.gifalert("Computer Name = " + WshNetwork.ComputerName);
None.gifalert("User Name = " + WshNetwork.UserName);//
None.gif
None.gif 
None.gif138.比较时间
None.gif  tDate = new Date(2004,01,08,14,35); //年,月,日,时,分
None.gif  dDate = new Date();
None.gif  tDate
< dDate ?alert("早于"):alert("晚于");//
None.gif
None.gif139.弹出鼠标所在处的链结地址
None.gif  <body onmouseover
="if (event.srcElement.tagName=='A')alert(event.srcElement.href)" ><
None.gif
None.gif
href ="http://51js.com/viewthread.php?tid=13589"   > dddd </ a >< input > //
None.gif
None.gif140.注意不能通过与 undefined 做比较来测试一个变量是否存在,虽然可以检查它的类型是否为“undefined”。在以
None.gif
None.gif下的代码范例中,假设程序员想测试是否已经声明变量 x :
None.gif// 这种方法不起作用
None.gifif (x == undefined)
None.gif    // 作某些操作
None.gif// 这个方法同样不起作用- 必须检查
None.gif
None.gif
None.gif// 字符串 "undefined"
None.gifif (typeof(x) == undefined)
None.gif    // 作某些操作
None.gif// 这个方法有效
None.gifif (typeof(x) == "undefined")
None.gif    // 作某些操作
None.gif
None.gif141.创建具有某些属性的对象
None.gifvar myObject = new Object();
None.gifmyObject.name = "James";
None.gifmyObject.age = "22";
None.gifmyObject.phone = "555 1234";// 
None.gif
None.gif142.枚举(循环)对象的所有属性
None.giffor (var a in myObject)
None.gif{
None.gif    // 显示 "The property 'name' is James",等等。
None.gif    window.alert("The property '" + a + "' is " + myObject[a]);
None.gif}//
None.gif
None.gif143.判断一个数字是否是整数
None.gifvar a=23.2;
None.gifalert(a%1==1)//
None.gif
None.gif
None.gif144.新建日期型变量
None.gifvar a = new Date(2000, 1, 1);
None.gifalert(a.toLocaleDateString());
None.gif
None.gif
None.gif145.给类定义新的方法
None.giffunction trim_1()
None.gif{
None.gif  return this.replace(/(^\s*)|(\s*$)/g, "");
None.gif}
None.gifString.prototype.trim=trim_1;
None.gifalert('cindy'.trim());
None.gif
None.gif 
None.gif146.定义一个将日期类型转化为字符串的方法
None.giffunction guoguo_date()
None.gif{
None.gif var tmp1,tmp2;
None.gif tmp1 =this.getMonth()+1+"";
None.gif if(tmp1.length
< 2 )
None.gif  tmp1
="0" +tmp1;
None.gif tmp2 
=this.getDate()+"";
None.gif 
if(tmp2.length<2)
None.gif  tmp2
="0" +tmp2;
None.gif 
None.gif return this.getYear()+"-"+tmp1+"-"+tmp2;
None.gif}
None.gifDate.prototype.toLiteString
=guoguo_date;
None.gif
alert(new Date().toLiteString())
None.gif
None.gif 
None.gif
None.gif147. pasta 是有四个参数的构造器,定义对象。
None.giffunction pasta(grain, width, shape, hasEgg)
None.gif{
None.gif    // 是用什么粮食做的?
None.gif    this.grain 
= grain;
None.gif
None.gif    
// 多宽?(数值)
None.gif    this.width 
= width;     
None.gif
None.gif    
// 横截面形状?(字符串)
None.gif    this.shape 
= shape;   
None.gif
None.gif    
// 是否加蛋黄?(boolean)
None.gif    this.hasEgg 
= hasEgg;  
None.gif
None.gif    
//定义方法
None.gif    this.toString
=aa;
None.gif
}
None.giffunction aa()
None.gif{
None.gif ;
None.gif}
None.gif//定义了对象构造器后,用 new 运算符创建对象实例。
None.gifvar spaghetti 
= new  pasta("wheat", 0.2, "circle", true);
None.gifvar linguine 
= new  pasta("wheat", 0.3, "oval", true);
None.gif//补充定义属性,spaghetti和linguine都将自动获得新的属性
None.gifpasta.prototype.foodgroup 
= "carbohydrates" ;
None.gif
None.gif 
None.gif148.打印出错误原因
None.giftry
None.gif{
None.gif x 
= y    // 产生错误。
None.gif}
None.gifcatch(e)
None.gif{
None.gif   document.write(e.description)   //打印 "'y' is undefined".
None.gif}//
None.gif
None.gif149.生成EXCEL文件并保存
None.gifvar ExcelSheet;
None.gifExcelApp 
= new  ActiveXObject("Excel.Application");
None.gifExcelSheet 
= new  ActiveXObject("Excel.Sheet");
None.gif//本代码启动创建对象的应用程序(在这种情况下,Microsoft Excel 工作表)。一旦对象被创建,就可以用定义的对
None.gif
None.gif象变量在代码中引用它。 在下面的例子中,通过对象变量 ExcelSheet 访问新对象的属性和方法和其他 Excel 对象,
None.gif
None.gif包括 Application 对象和 ActiveSheet.Cells 集合。 
None.gif// 使 Excel 通过 Application 对象可见。
None.gifExcelSheet.Application.Visible 
= true;
None.gif
// 将一些文本放置到表格的第一格中。
None.gifExcelSheet.ActiveSheet.Cells(1,1).Value 
= "This is column A, row 1" ;
None.gif// 保存表格。
None.gifExcelSheet.SaveAs("C:\\TEST.XLS");
None.gif// 用 Application 对象用 Quit 方法关闭 Excel。
None.gifExcelSheet.Application.Quit();//
None.gif
None.gif150.根据标签获得一组对象
None.gifvar coll 
= document.all.tags("DIV");
None.gif
if (coll! =null)
None.gif
{
None.giffor (i
=0;  i<coll.length; i++) 
None.gifdot.gif
None.gif}//
None.gif    
None.gif151.实现打印预览及打印
None.gif<OBJECT classid
="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"  height =0  id =wb  name =wb  width =0 ></ OBJECT >  
None.gif
< input  type =button  value =打印预览  onclick ="wb.execwb(7,1)" >
None.gif
< input  type =button  onClick =document.all.wb.ExecWB(6,1)  value ="打印" > //
None.gif
None.gif152.不通过form,直接通过名字引用对象
None.gif
< INPUT  TYPE ="text"  NAME ="gg"  value =aaaaa >
ExpandedBlockStart.gif
< SCRIPT  LANGUAGE ="JavaScript" >
InBlock.gif
<!--
InBlock.gifalert(document.all.gg.value)
ExpandedBlockEnd.gif
//-->
None.gif
</ SCRIPT > //
None.gif
None.gif153.使鼠标滚轮失效
None.giffunction document.onmousewheel()
None.gif{
None.gif return false;
None.gif}//
None.gif 
None.gif154.创建弹出窗口
ExpandedBlockStart.gif
< SCRIPT  LANGUAGE ="JScript" >
InBlock.gif  
var oPopup = window.createPopup();
InBlock.gif  
var oPopupBody = oPopup.document.body;
InBlock.gif  oPopupBody.innerHTML 
= "Display some <B>HTML</B> here.";
ExpandedBlockEnd.gif  oPopup.show(
10010020050, document.body);
None.gif
</ SCRIPT > //
None.gif
None.gif155.取得鼠标所在处的对象
None.gifvar obj = document.elementFromPoint(event.x,event.y);//
None.gif
None.gif156.获得左边的对象
None.gif
< INPUT  TYPE ="text"  NAME ="gg" >< INPUT  TYPE ="text"  NAME ="bb"  
None.gif
None.gifonclick
="this.previousSibling.value='guoguo'" > //
None.gif
None.gif157.定位鼠标
None.gifdocument.all.hint_layer.style.left  = event.x+document.body.scrollLeft+10;
None.gifdocument.all.hint_layer.style.top  = event.y+document.body.scrollTop+10;//
None.gif
None.gif158.向下拉框指定位置添加项目
None.gifvar op  = document.createElement("OPTION");
None.gifdocument.all.selected_items.children(index).insertAdjacentElement("BeforeBegin",op);
None.gifop.text  = document.all.all_items[i].text;
None.gifop.value = document.all.all_items[i].value;//
None.gif
None.gif 
None.gif159.判断一个窗口是否已经打开,如果已经打开,则关闭之
None.gifvar a;
None.gifif(a) 
None.gif a.close();
None.gifelse
None.gif a=window.open('','','');//
None.gif
None.gif160.动态创建一个标签
None.gifnewElem  = document.createElement("DIV");
None.gifnewElem.id = "hint_layer";
None.gifdocument.body.appendChild(newElem);
None.gifdocument.all.hint_layer.innerText="guoguo";//
None.gif
None.gif161.标题栏
None.gifdocument.title//
None.gif
None.gif162.背景图片
None.gif
< body  style ="BACKGROUND-ATTACHMENT: fixed"  background ="img/bgfix.gif"   ></ body > //背景图片不动
None.gif
ExpandedBlockStart.gif
< STYLE  TYPE ="text/css" >
InBlock.gif<!--
ExpandedSubBlockStart.gifBODY 
{background-image:img/bgchild.jpg;
InBlock.gifbackground-position
: center;
InBlock.gifbackground-repeat
: no-repeat;
ExpandedSubBlockEnd.gifbackground-attachment
: fixed;}

ExpandedBlockEnd.gif-->
None.gif
</ STYLE > //背景图片居中
None.gif
None.gif163.设置透明效果
None.gifdocument.form.xxx.filters.alpha.opacity=0~100//
None.gif
None.gif164.定义方法
None.gifvar dragapproved=false;
None.gifdocument.onmouseup=new Function("dragapproved = false");//
None.gif 
None.gif165.将数字转化为人民币大写形式
None.giffunction convertCurrency(currencyDigits) {
None.gif// Constants:
None.gif var MAXIMUM_NUMBER = 99999999999.99;
None.gif // Predefine the radix characters and currency symbols for output:
None.gif var CN_ZERO = "零";
None.gif var CN_ONE = "壹";
None.gif var CN_TWO = "贰";
None.gif var CN_THREE = "叁";
None.gif var CN_FOUR = "肆";
None.gif var CN_FIVE = "伍";
None.gif var CN_SIX = "陆";
None.gif var CN_SEVEN = "柒";
None.gif var CN_EIGHT = "捌";
None.gif var CN_NINE = "玖";
None.gif var CN_TEN = "拾";
None.gif var CN_HUNDRED = "佰";
None.gif var CN_THOUSAND = "仟";
None.gif var CN_TEN_THOUSAND = "万";
None.gif var CN_HUNDRED_MILLION = "亿";
None.gif var CN_SYMBOL = "人民币";
None.gif var CN_DOLLAR = "元";
None.gif var CN_TEN_CENT = "角";
None.gif var CN_CENT = "分";
None.gif var CN_INTEGER = "整";
None.gif 
None.gif// Variables:
None.gif var integral; // Represent integral part of digit number.
None.gif var decimal; // Represent decimal part of digit number.
None.gif var outputCharacters; // The output result.
None.gif var parts;
None.gif var digits, radices, bigRadices, decimals;
None.gif var zeroCount;
None.gif var i, p, d;
None.gif var quotient, modulus;
None.gif 
None.gif// Validate input string:
None.gif currencyDigits = currencyDigits.toString();
None.gif if (currencyDigits == "") {
None.gif  alert("Empty input!");
None.gif  return "";
None.gif }
None.gif if (currencyDigits.match(/[^,.\d]/) != null) {
None.gif  alert("Invalid characters in the input string!");
None.gif  return "";
None.gif }
None.gif if ((currencyDigits).match(/^((\d{1,3}(,\d{3})*(.((\d{3},)*\d{1,3}))?)|(\d+(.\d+)?))$/) == null) {
None.gif  alert("Illegal format of digit number!");
None.gif  return "";
None.gif }
None.gif 
None.gif// Normalize the format of input digits:
None.gif currencyDigits = currencyDigits.replace(/,/g, ""); // Remove comma delimiters.
None.gif currencyDigits = currencyDigits.replace(/^0+/, ""); // Trim zeros at the beginning.
None.gif // Assert the number is not greater than the maximum number.
None.gif if (Number(currencyDigits) > MAXIMUM_NUMBER) {
None.gif  alert("Too large a number to convert!");
None.gif  return "";
None.gif }
None.gif 
None.gif// Process the coversion from currency digits to characters:
None.gif // Separate integral and decimal parts before processing coversion:
None.gif parts = currencyDigits.split(".");
None.gif if (parts.length > 1) {
None.gif  integral = parts[0];
None.gif  decimal = parts[1];
None.gif  // Cut down redundant decimal digits that are after the second.
None.gif  decimal = decimal.substr(0, 2);
None.gif }
None.gif else {
None.gif  integral = parts[0];
None.gif  decimal = "";
None.gif }
None.gif // Prepare the characters corresponding to the digits:
None.gif digits = new Array(CN_ZERO, CN_ONE, CN_TWO, CN_THREE, CN_FOUR, CN_FIVE, CN_SIX, CN_SEVEN, CN_EIGHT, 
None.gif
None.gifCN_NINE);
None.gif radices = new Array("", CN_TEN, CN_HUNDRED, CN_THOUSAND);
None.gif bigRadices = new Array("", CN_TEN_THOUSAND, CN_HUNDRED_MILLION);
None.gif decimals = new Array(CN_TEN_CENT, CN_CENT);
None.gif // Start processing:
None.gif outputCharacters = "";
None.gif // Process integral part if it is larger than 0:
None.gif if (Number(integral) > 0) {
None.gif  zeroCount = 0;
None.gif  for (i = 0; i 
<  integral .length; i++) {
None.gif   p 
= integral.length  - i - 1;
None.gif   d 
= integral.substr(i,  1);
None.gif   quotient 
= p  / 4;
None.gif   modulus 
= p  % 4;
None.gif   if (d 
==  "0") {
None.gif    zeroCount++;
None.gif   }
None.gif   else {
None.gif    if (zeroCount 
>  0)
None.gif    {
None.gif     outputCharacters += digits[0];
None.gif    }
None.gif    zeroCount = 0;
None.gif    outputCharacters += digits[Number(d)] + radices[modulus];
None.gif   }
None.gif   if (modulus == 0 && zeroCount 
<  4 ) {
None.gif    outputCharacters +
= bigRadices[quotient];
None.gif   
}
None.gif  }
None.gif  outputCharacters +
= CN_DOLLAR;
None.gif 
}
None.gif // Process decimal part if there is:
None.gif if (decimal !
= "" ) {
None.gif  for (i 
= 0;  i < decimal.length; i++) {
None.gif   d 
= decimal.substr(i,  1);
None.gif   if (d !
= "0" ) {
None.gif    outputCharacters +
= digits[Number(d)]  + decimals[i];
None.gif   }
None.gif  }
None.gif }
None.gif // Confirm and return the final output string:
None.gif if (outputCharacters 
==  "") {
None.gif  outputCharacters 
= CN_ZERO  + CN_DOLLAR;
None.gif }
None.gif if (decimal 
==  "") {
None.gif  outputCharacters +
= CN_INTEGER;
None.gif 
}
None.gif outputCharacters 
= CN_SYMBOL  + outputCharacters;
None.gif return outputCharacters;
None.gif}//
None.gif
None.gif 
None.gif166.xml数据岛绑定表格
None.gif<html
>
None.gif
< body >
None.gif
< xml  id ="abc"  src ="test.xml" ></ xml >
None.gif
< table  border ='1'  datasrc ='#abc' >
None.gif
< thead >
None.gif
< td > 接收人 </ td >
None.gif
< td > 发送人 </ td >
None.gif
< td > 主题 </ td >
None.gif
< td > 内容 </ td >
None.gif
</ thead >
None.gif
< tfoot >
None.gif
< tr >< th > 表格的结束 </ th ></ tr >
None.gif
</ tfoot >
None.gif
< tr >
None.gif
< td >< div  datafld ="to" ></ div ></ td >
None.gif
< td >< div  datafld ="from" ></ div ></ td >
None.gif
< td >< div  datafld ="subject" ></ div ></ td >
None.gif
< td >< div  datafld ="content" ></ div ></ td >
None.gif
</ tr >
None.gif
</ table >
None.gif
</ body >
None.gif
</ html >
None.gif
None.gif//cd_catalog.xml
None.gif
<? xml version="1.0" encoding="ISO-8859-1"  ?>  
None.gif 
<!--   Edited with XML Spy v4.2 
None.gif  
-->  
None.gif 
< CATALOG >
None.gif 
< CD >
None.gif  
< TITLE > Empire Burlesque </ TITLE >  
None.gif  
< ARTIST > Bob Dylan </ ARTIST >  
None.gif  
< COUNTRY > USA </ COUNTRY >  
None.gif  
< COMPANY > Columbia </ COMPANY >  
None.gif  
< PRICE > 10.90 </ PRICE >  
None.gif  
< YEAR > 1985 </ YEAR >  
None.gif  
</ CD >
None.gif 
< CD >
None.gif  
< TITLE > Hide your heart </ TITLE >  
None.gif  
< ARTIST > Bonnie Tyler </ ARTIST >  
None.gif  
< COUNTRY > UK </ COUNTRY >  
None.gif  
< COMPANY > CBS Records </ COMPANY >  
None.gif  
< PRICE > 9.90 </ PRICE >  
None.gif  
< YEAR > 1988 </ YEAR >  
None.gif  
</ CD >
None.gif 
< CD >
None.gif  
< TITLE > Greatest Hits </ TITLE >  
None.gif  
< ARTIST > Dolly Parton </ ARTIST >  
None.gif  
< COUNTRY > USA </ COUNTRY >  
None.gif  
< COMPANY > RCA </ COMPANY >  
None.gif  
< PRICE > 9.90 </ PRICE >  
None.gif  
< YEAR > 1982 </ YEAR >  
None.gif  
</ CD >
None.gif 
< CD >
None.gif  
< TITLE > Still got the blues </ TITLE >  
None.gif  
< ARTIST > Gary Moore </ ARTIST >  
None.gif  
< COUNTRY > UK </ COUNTRY >  
None.gif  
< COMPANY > Virgin records </ COMPANY >  
None.gif  
< PRICE > 10.20 </ PRICE >  
None.gif  
< YEAR > 1990 </ YEAR >  
None.gif  
</ CD >
None.gif
</ CATALOG >
None.gif//
None.gif
None.gif
None.gif167.以下组合可以正确显示汉字
None.gif================================
None.gifxml保存编码 xml页面指定编码
None.gifANSI  gbk/GBK、gb2312
None.gifUnicode  unicode/Unicode
None.gifUTF-8  UTF-8
None.gif================================
None.gif
None.gif 
None.gif168.XML操作
None.gif
< xml  id ="xmldata"  src ="/data/books.xml" >
None.gif
< div  id ="guoguo" ></ div >
ExpandedBlockStart.gif
< script >
InBlock.gif
var x=xmldata.recordset //取得数据岛中的记录集
InBlock.gif
if(x.absoluteposition < x.recordcount) //如果当前的绝对位置在最后一条记录之前
ExpandedSubBlockStart.gif
{
InBlock.gif x.movenext();     
//向后移动
InBlock.gif
 x.moveprevious();    //向前移动
InBlock.gif
 x.absoluteposition=1;   //移动到第一条记录
InBlock.gif
 x.absoluteposition=x.recordcount;//移动到最后一条记录,注意记录集x.absoluteposition是从1到记录集记录的个
InBlock.gif

InBlock.gif数的
InBlock.gif guoguo.innerText
=xmldso.recordset("field_name"); //从中取出某条记录
ExpandedBlockEnd.gif
}

None.gif
</ script >
None.gif
None.gif 
None.gif169.动态修改CSS的另一种方式
None.gifthis.runtimeStyle.cssText = "color:#990000;border:1px solid #cccccc";//
None.gif
None.gif170.正则表达式
None.gif匹配中文字符的正则表达式: [\u4e00-\u9fa5]
None.gif
None.gif匹配双字节字符(包括汉字在内):[^\x00-\xff]
None.gif
None.gif应用:计算字符串的长度(一个双字节字符长度计2,ASCII字符计1)
None.gif
None.gifString.prototype.len=function(){return this.replace([^\x00-\xff]/g,"aa").length;}
None.gif
None.gif匹配空行的正则表达式:\n[\s| ]*\r
None.gif
None.gif匹配HTML标记的正则表达式:/
< (.*) > .* < \/\1 > | < (.*) \ />
None.gif
None.gif匹配首尾空格的正则表达式:(^\s*)|(\s*$)
None.gif
None.gif应用:javascript中没有像vbscript那样的trim函数,我们就可以利用这个表达式来实现,如下:
None.gif
None.gifString.prototype.trim = function()
None.gif{
None.gif    return this.replace(/(^\s*)|(\s*$)/g, "");
None.gif}
None.gif
None.gif////////利用正则表达式分解和转换IP地址:
None.gif
None.gif下面是利用正则表达式匹配IP地址,并将IP地址转换成对应数值的Javascript程序:
None.gif
None.giffunction IP2V(ip)
None.gif{
None.gif re=/(\d+)\.(\d+)\.(\d+)\.(\d+)/g  //匹配IP地址的正则表达式
None.gifif(re.test(ip))
None.gif{
None.gifreturn RegExp.$1*Math.pow(255,3))+RegExp.$2*Math.pow(255,2))+RegExp.$3*255+RegExp.$4*1
None.gif}
None.gifelse
None.gif{
None.gif throw new Error("Not a valid IP address!")
None.gif}
None.gif}
None.gif
None.gif不过上面的程序如果不用正则表达式,而直接用split函数来分解可能更简单,程序如下:
None.gif
None.gifvar ip="10.100.20.168"
None.gifip=ip.split(".")
None.gifalert("IP值是:"+(ip[0]*255*255*255+ip[1]*255*255+ip[2]*255+ip[3]*1))
None.gif
None.gif匹配Email地址的正则表达式:\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
None.gif
None.gif匹配网址URL的正则表达式:http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?
None.gif
None.gif//////////利用正则表达式去除字串中重复的字符的算法程序:
None.gif
None.gifvar s="abacabefgeeii"
None.gifvar s1=s.replace(/(.).*\1/g,"$1")
None.gifvar re=new RegExp("["+s1+"]","g")
None.gifvar s2=s.replace(re,"") 
None.gifalert(s1+s2)  //结果为:abcefgi
None.gif
None.gif思路是使用后向引用取出包括重复的字符,再以重复的字符建立第二个表达式,取到不重复的字符,两者串连。这个方
None.gif
None.gif法对于字符顺序有要求的字符串可能不适用。
None.gif
None.gif//////////得用正则表达式从URL地址中提取文件名的javascript程序,如下结果为page1
None.gif
None.gifs="http://www.9499.net/page1.htm"
None.gifs=s.replace(/(.*\/){0,}([^\.]+).*/ig,"$2")
None.gifalert(s)
None.gif
None.gif/////////利用正则表达式限制网页表单里的文本框输入内容:
None.gif
None.gif用正则表达式限制只能输入中文:onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,'')" 
None.gif
None.gifonbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\u4E00-\u9FA5]/g,'')
None.gif
None.gif)"
None.gif
None.gif用正则表达式限制只能输入全角字符: onkeyup="value=value.replace(/[^\uFF00-\uFFFF]/g,'')" 
None.gif
None.gifonbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\uFF00-\uFFFF]/g,'')
None.gif
None.gif)"
None.gif
None.gif用正则表达式限制只能输入数字:onkeyup="value=value.replace(/[^\d]/g,'') 
None.gif
None.gif"onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"
None.gif
None.gif用正则表达式限制只能输入数字和英文:onkeyup="value=value.replace(/[\W]/g,'') 
None.gif
None.gif"onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"
None.gif
None.gif 
None.gif171.设置和使用cookie
None.gif
< HTML >
None.gif
< BODY >
None.gif设置与读取 cookiesdot.gif
< BR >
None.gif写入cookie的值
< input  type =text  name =gg >
None.gif
< INPUT  TYPE  = BUTTON  Value  = "设置cookie"  onClick  = "Set()" >
None.gif
< INPUT  TYPE  = BUTTON  Value  = "读取cookie"  onClick  = "Get()" >< BR >
None.gif
< INPUT  TYPE  = TEXT  NAME  = Textbox >
None.gif
</ BODY >
ExpandedBlockStart.gif
< SCRIPT  LANGUAGE ="JavaScript" >
InBlock.gif
function Set()
ExpandedSubBlockStart.gif
{
InBlock.gif
var Then = new Date() 
InBlock.gifThen.setTime(Then.getTime() 
+ 60*1000 ) //60秒
InBlock.gif
document.cookie = "Cookie1="+gg.value+";expires="+ Then.toGMTString() 
ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
function Get()
ExpandedSubBlockStart.gif

InBlock.gif 
var cookieString = new String(document.cookie)
InBlock.gif 
var cookieHeader = "Cookie1="
InBlock.gif 
var beginPosition = cookieString.indexOf(cookieHeader)
InBlock.gif 
if (beginPosition != -1)
ExpandedSubBlockStart.gif 
{
InBlock.gif  document.all.Textbox.value 
= cookieString.substring(beginPosition  + cookieHeader.length) 
ExpandedSubBlockEnd.gif }

InBlock.gif 
else
InBlock.gif  document.all.Textbox.value 
= "Cookie 未找到!" 
ExpandedBlockEnd.gif}

None.gif
</ SCRIPT >  
None.gif
</ HTML > //
None.gif
None.gif 
None.gif172.取月的最后一天
None.giffunction getLastDay(year,month)
None.gif{
None.gif //取年
None.gif var new_year = year;
None.gif //取到下一个月的第一天,注意这里传入的month是从1~12 
None.gif var new_month = month++;
None.gif //如果当前是12月,则转至下一年
None.gif if(month>12)
None.gif {
None.gif  new_month -=12;
None.gif  new_year++;
None.gif }
None.gif var new_date = new Date(new_year,new_month,1);
None.gif return (new Date(new_date.getTime()-1000*60*60*24)).getDate();
None.gif}//
None.gif
None.gif173.判断当前的焦点是组中的哪一个
None.giffor(var i=0;i
< 3 ;i++)
None.gif if(event.srcElement
==bb[i])
None.gif  
break;//
None.gif
None.gif 
None.gif
None.gif174.实现类
None.gifpackage com.baosight.view.utils;
None.gifimport javax.servlet.jsp.tagext.TagSupport;
None.gifimport javax.servlet.http.HttpSession;
None.gifpublic class Mytag extends TagSupport 
None.gif{
None.gif  public int doStartTag() throws javax.servlet.jsp.JspException 
None.gif  {
None.gif    boolean canAccess 
= false;
None.gif    
HttpSession session = pageContext.getSession();
None.gif    
if (canAccess) 
None.gif    {
None.gif      return EVAL_BODY_INCLUDE;
None.gif    }
None.gif    else 
None.gif    {
None.gif      return this.SKIP_BODY;
None.gif    }
None.gif  }
None.gif}
None.gif
None.gif175.在web.xml中添加定义
None.gif  <taglib
>
None.gif    
< taglib-uri > guoguo </ taglib-uri >
None.gif    
< taglib-location > /WEB-INF/abc.tld </ taglib-location >
None.gif  
</ taglib >
None.gif
None.gif
None.gif176.标签库中定义abc.tld
None.gif
<? xml version="1.0" encoding="UTF-8" ?>
None.gif
<! DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN" 
None.gif"http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd"
>
None.gif
< taglib >
None.gif 
< tlibversion > 1.0 </ tlibversion >
None.gif 
< jspversion > 1.1 </ jspversion >
None.gif 
< shortname > hr </ shortname >
None.gif 
< uri > guoguo </ uri >
None.gif 
< info > Extra 3 Tag Library </ info >
None.gif 
< tag >
None.gif  
< name > mytag </ name >
None.gif  
< tagclass > com.baosight.view.utils.Mytag </ tagclass >
None.gif  
< attribute >
None.gif   
< name > id2 </ name >
None.gif   
< required > true </ required >
None.gif            
< rtexprvalue > true </ rtexprvalue >
None.gif  
</ at