javascript 常用代码技巧大收集
程序员文章站
2022-06-29 09:10:36
1.文本框焦点问题 onblur:当失去输入焦点后产生该事件 onfocus:当输入获得焦点后,产生该文件 onchange:当文字值改变时,产生该事件 onselect:...
1.文本框焦点问题
onblur:当失去输入焦点后产生该事件
onfocus:当输入获得焦点后,产生该文件
onchange:当文字值改变时,产生该事件
onselect:当文字加亮后,产生该文件
<input type="text" value="郭强" onfocus="if(value=='郭强') {value=''}" onblur="if
(value=='') {value='郭强'}">点击时文字消失,失去焦点时文字再出现
2.网页按钮的特殊颜色
<input type=button name="submit1" value="郭强" size=10 class=s02
style="background-color:rgb(235,207,22)">
3.鼠标移入移出时颜色变化
<input type="submit" value="找吧" name="b1" onmouseout=this.style.color="blue"
onmouseover=this.style.color="red" class="button">
4.平面按钮
<input type=submit value=订阅 style="border:1px solid :#666666; height:17px; width:25pt; font-size:9pt;
background-color: #e8e8ff; color:#666666" name="submit">
5.按钮颜色变化
<input type=text name="nick" style="border:1px solid #666666; font-size:9pt; height:17px;
background-color: #f4f4ff; color:#ff6600" size="15" maxlength="16">
6.平面输入框
<input type="text" name="t1" size="20" style="border-style: solid; border-width: 1">
7.使窗口变成指定的大小
<script>
window.resizeto(300,283);
</script>
8.使文字上下滚动
<marquee direction=up scrollamount=1 scrolldelay=100 onmouseover='this.stop()' onmouseout='this.start()'
height=60>
<!-- head_scrolltext -->
<tr>
<td>
*
</table> <!-- end head_scrolltext -->
</marquee>
9.状态栏显示该页状态
<base onmouseover="window.status='网站建设 http://www.webmake.cn/' ;return true">
10.可以点击文字实现radio选项的选定
<br>
<input type="radio" name="regtype" value="a03" id="a03">
<label for="a03"> 情侣 : 一次注册两个帐户</label> <br>
11.可以在文字域的font写onclick事件
12.打印
<a href='javascript:window.print ()'> </a>打印网页
13.线型输入框
<input type="text" name="key" size="12" value="关键字" onfocus=this.select() onmouseover=this.focus()
class="line">
14.显示文档最后修改日期
<script language=javascript>
function hi(str)
{
document.write(document.lastmodified)
alert("hi"+str+"!")
}
</script>
15.可以在鼠标移到文字上时就触发事件
<html>
<head>
<script language="livescript">
<!-- hiding
function hello() {
alert("哈罗!");
}
</script>
</head>
<body>
<a href="" onmouseover="hello()">link</a>
</body>
</html>
16.可以根据网页上的选项来确定页面颜色
<html>
<head>
<title>background.html</title>
</head>
<script>
<!--
function bgchange(selobj) {
newcolor = selobj.options[selobj.selectedindex].text;
document.bgcolor = newcolor;
selobj.selectedindex = -1;
}
//-->
</script>
<body style="font-family:arial">
<b>changing background colors</b>
<br>
<form>
<select size="8" onchange="bgchange(this);">
<option>red
<option>orange
<option>yellow
<option>green
<option>blue
<option>indigo
<option>violet
<option>white
<option>pink
</select>
</form>
</body>
</html>
17.将按钮的特征改变
<style type="text/css">
<!--
.style1 { font-size: 12px; background: #ccccff; border-width: thin thin thin thin; border-color: #ccccff
#cccccc #cccccc #ccccff}
.style2 { font-size: 12px; font-weight: bold; background: #ccffcc; border-width: thin medium medium thin;
border-color: #ccff99 #999999 #999999 #ccff99}
-->
</style>
本例按钮的代码如下:
<input type="submit" name="submit" value="提 交" onmouseover="this.classname='style2'"
onmouseout="this.classname='style1'" class="style1">
18.改变按钮的图片.
<style type="text/css">
<!--
.style3 { font-size: 12px; background: url(image/buttonbg1.gif); border: 0px; width: 60px; height: 22px}
.style4 { font-size: 12px; font-weight: bold; background: url(image/buttonbg2.gif); border: 0px 0; width:
60px; height: 22px}
-->
</style>
本例的按钮代码如下:
<input type="submit" name="submit2" value="提 交" onmouseover="this.classname='style4'"
onmouseout="this.classname='style3'" class="style3">
19.打印页面
<div align="center"><a class=content href="javascript:doprint();">打印本稿</a></div>
20.可以直接写html语言
document.write("");
21.改变下拉框的颜色
<select name="classid"
onchange="changelocation(document.myform.classid.options[document.myform.classid.selectedindex].value)"
size="1" style="color:#008080;font-size: 9pt">
22.转至目标url
window.location=http://blog.csdn.net/lxs5i5j/archive/2007/01/22/"http://guoguo"
23.传递该object的form
updatesn('guoqiang99267',this.form)
function updatesn(strvalue,strform)
{
strform.signinname.value = strvalue;
return false;
}
24.文字标签
<label for="altname4"><input name="altname" type="radio" tabindex="931" id="altname4"
>guoqiang99859</label>
25.layer2为组件的id,可以控制组件是否可见
document.all.item('layer2').style.display = "block";
document.all.item('layer2').style.display = "none";//
26.将页面加入favorite中
<script language=javascript>
<!--
function addme(){
url = http://blog.csdn.net/lxs5i5j/archive/2007/01/22/"http://your.site.address"; //你自己的主页地址
title = "your site name"; //你自己的主页名称
window.external.addfavorite(url,title);
-->
</script>//
27.过10秒自动关闭页面
< script language="javascript" >
function closeit() {
settimeout("self.close()",10000)
}
< /script >
28.可以比较字符的大小
char=post.charat(i);
if(!('0'<=char&&char<='9'))
29.将字符转化为数字
month = parseint(char)
30.点击value非空的选项时转向指定连接
<select onchange='if(this.value!="")window.open(this.value)' class="textinput">
<option selected>主办单位</option>
<option>-----------------</option>
<option value=http://blog.csdn.net/lxs5i5j/archive/2007/01/22/"http://www.bjd.com.cn/">北京日报</option>
<option value=http://blog.csdn.net/lxs5i5j/archive/2007/01/22/"http://www.ben.com.cn/">北京晚报</option>
</select>
31.改变背景颜色
<td width=* class=dp bgcolor=#fafbfc onmouseover="this.bgcolor='#ffffff';"
onmouseout="this.bgcolor='#fafbfc';">
32.改变文字输入框的背景颜色
<style>
.input2 {background-image: url('../images/inputbg.gif'); font-size: 12px; background-color:
#d0dabb;border-top-width:1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px}
</style>
<input name=content type=text size="47" class="input2" maxlength="50">
33.改变水平线的特征
<hr size="0" noshade color="#c0c0c0">
34.传递参数的方式
<a href="vote.asp?curpage=8&id=3488">8</a>
35.页内跳转
<a href="#1">1</a>
<a href="#2">2</a>
<a href="#3">3</a>
<a href="#4">4</a>
<a href="#5">5</a>
<a href="#6">6</a>
<a href="#7">7</a>
<a name="1">dfdf</a>
<a name="2">dfdf</a>//
36.两个按键一起按下
if(event.ctrlkey && window.event.keycode==13)//
37.刷新页面
javascript:this.location.reload()//
38.将网页的按钮使能
<script language="javascript">
function haha()
{
for(var i=0;i<document.form1.elements.length;i++)
{
if(document.form1.elements[i].name.indexof("bb")!=-1)
document.form1.elements[i].disabled=!document.form1.elements[i].disabled;
}
}
</script>
<body><form name=form1>
<input type="button" name="aa " value=cindy onclick=haha()>
<input type="button" name="bb " value=guoguo>
<input type="button" name="bb " value=guoguo>
39.文字移动
<marquee scrollamount=3 onmouseover=this.stop(); onmouseout=this.start();>
40.双击网页自动跑
<script language="javascript">
var currentpos,timer;
function initialize()
{
timer=setinterval("scrollwindow()",1);
}
function sc()
{
clearinterval(timer);
}
function scrollwindow()
{
currentpos=document.body.scrolltop;
window.scroll(0,++currentpos);
if (currentpos != document.body.scrolltop)
sc();
}
document.onmousedown=sc
document.ondblclick=initialize
</script>//
41.后退
<input type="button" onclick=window.history.back() value=back>
42.前进
<input type="button" onclick=window.history.forward() value=forward>
43.刷新
<input type="button" onclick=document.location.reload() value=reload>
44.转向指定网页
document.location=http://blog.csdn.net/lxs5i5j/archive/2007/01/22/"http://ww"或者document.location.assign(http://blog.csdn.net/lxs5i5j/archive/2007/01/22/"http://guoguo.com")
45.在网页上显示实时时间
<script language="javascript">
var clock_id;
window.onload=function()
{
clock_id=setinterval("document.form1.txtclock.value=(new date);",1000)
}
</script>//
46.可以下载文件
document.location.href="目标文件"//
47.连接数据库
import java.sql.*;
string mydbdriver="sun.jdbc.odbc.jdbcodbcdriver";
class.forname(mydbdriver);
connection conn=drivermanager.getconnection("jdbc:odbc:firm","username","password");
statement stmt=conn.createstatement();
resultset rs=stmt.executequery(sql);
rs.getstring("column1");//
48.可以直接在页面“div”内写下所需内容
<input type="button" onclick="a1.innerhtml='<font color=red>*</font>'">
<div id=a1></div>//
49.可以改变页面上的连接的格式,使其为双线
<style>
a:link {text-decoration: none; color:#0000ff; font-family: 宋体}
a:visited {text-decoration: none; color: #0000ff; font-family: 宋体}
a:hover {text-decoration: underline overline; color: ff0000}
</style>
<style>
a:link {text-decoration: none; color:#0000ff; font-family: 宋体}
a:visited {text-decoration: none; color: #0000ff; font-family: 宋体}
a:hover {text-decoration: underline overline line-through; color: ff0000}
th{font-size: 9pt}
td{font-size: 9pt}
body {scrollbar-face-color: #a9d46d; scrollbar-highlight-color: #e7e7e7;scrollbar-shadow-color:#e7e7e7;
scrollbar-3dlight-color: #000000; line-height: 15pt; scrollbar-arrow-color: #ffffff;
scrollbar-track-color: #e7e7e7;}
input{border-top-width: 1px; padding-right: 1px; padding-left: 1px; border-left-width: 1px; font-size:
9pt; border-left-color: #cccccc;
border-bottom-width: 1px; border-bottom-color: #cccccc; padding-bottom: 1px; border-top-color: #cccccc;
padding-top: 1px; height: 18px; border-right-width: 1px; border-right-color: #cccccc}
div,form ,option,p,td,br{font-family: 宋体; font-size: 9pt}
textarea, select {border-width: 1; border-color: #000000; background-color: #efefef; font-family: 宋体;
font-size: 9pt; font-style: bold;}
.text { font-family: "宋体"; font-size: 9pt; color: #003300; border: #006600 solid; border-width: 1px 1px
1px 1px}
</style>完整的css
50.新建frame
<a
href="javascript:newframe('http://www.163.net/help/a_little/index.html','http://www.163.net/help/a_little
/a_13.html')"><img alt=帮助 border=0 src=http://blog.csdn.net/lxs5i5j/archive/2007/01/22/"http://bjpic.163.net/images/mail/button-help.gif"></a>
51.向文件中写内容
<%@ page import="java.io.*" %>
<%
string str = "print me";
//always give the path from root. this way it almost always works.
string nameoftextfile = "/usr/anil/imp.txt";
try
{
printwriter pw = new printwriter(new fileoutputstream(nameoftextfile));
pw.println(str);
//clean up
pw.close();
}
catch(ioexception e)
{
out.println(e.getmessage());
}
%>
52.先读文件再写文件
<%@ page language = "java" %>
<%@ page contenttype = "text/html; charset=gb2312" %>
<%@ page import ="java.util.*" %>
<%@ page import ="java.lang.*" %>
<%@ page import ="javax.servlet.*" %>
<%@ page import ="javax.servlet.jsp.*" %>
<%@ page import ="javax.servlet.http.*" %>
<%@ page import="java.io.*" %>
eryrytry
<%
int count=0;
fileinputstream fi =new fileinputstream ("count.txt");
objectinputstream si= new objectinputstream (fi);
count =si.readint();
count++;
out.print(count);
si.close();
fileoutputstream fo =new fileoutputstream ("count.txt");
objectoutputstream so= new objectoutputstream (fo);
so.writeint(count);
so.close();
%>
53.直线型输入框
<input name=password size=10 type=password style="border-left-width: 0; border-right-width: 0;
border-top-width: 0; border-bottom-style: solid; border-bottom-width: 1; background-color: #9ceb9c">
54.可以将背景改为按钮性状,通过改变css改变属性
<td width="65" align="center" bgcolor="#e0e0e0" onmouseover=this.classname='mouseoverbt';
onmouseout=this.classname='mouseout';><a href="tm.asp?classid=76"><font
color="#000000">录音笔</font></a></td>
<style>
.mouseoverbt
{
background-image: url(file:///c|/"><input type="submit" value="c:\ drive"></form>//
85.当前屏幕的分辨率
screen.width、screen.height//
86.设置表格中的内容
tbl.rows[0].cells[1].innertext=document.form.text1.value;//
87.本地快捷键
<p><a href=http://blog.csdn.net/lxs5i5j/archive/2007/01/22/"file:///::{208d2c60-3aea-1069-a2d7-08002b30309d}" target="_blank">网上邻居</a></p>
<p><a href=http://blog.csdn.net/lxs5i5j/archive/2007/01/22/"file:///::{20d04fe0-3aea-1069-a2d8-08002b30309d}\d:\web" target="_blank">我的电脑</a></p>
<p><a href=http://blog.csdn.net/lxs5i5j/archive/2007/01/22/"file:///::{450d8fba-ad25-11d0-98a8-0800361b1103}" target="_blank">我的文档</a></p>
<p><a href=http://blog.csdn.net/lxs5i5j/archive/2007/01/22/"file:///::{645ff040-5081-101b-9f08-00aa002f954e}" target="_blank">回收站</a></p>
<p><a href=http://blog.csdn.net/lxs5i5j/archive/2007/01/22/"file:///::{20d04fe0-3aea-1069-a2d8-08002b30309d}\::{21ec2020-3aea-1069-a2dd-08002b30309d}"
target="_blank">控制面板</a></p>
<p><a href=http://blog.csdn.net/lxs5i5j/archive/2007/01/22/"file:///::{7007acc7-3202-11d1-aad2-00805fc1270e}">拨号网络</a>(windows 2000)</p>
88.ie菜单
<button onclick="min.click()"><font face="webdings">0</font></button>//改变按钮上的图片
<input type=button onclick="document.execcommand('createlink','true','true')"> //创建新连接
<input type=button onclick="document.execcommand('print','true','true')"> //打印
<input type=button onclick="document.execcommand('saveas','true','网站制作.htm')">//另存为htm
<input type=button onclick="document.execcommand('saveas','true','网站制作.txt')">//另存为txt
document.execcommand("saveas")//保存为
document.execcommand('undo')//撤销上一次操作
89.web对话框
<script>
var contents='<style>body,td{font:menu}img{cursor:hand}</style>';
contents+='<title>你要关闭我吗</title>';
contents+='<body bgcolor=menu>';
contents+='<table width=100% height=100% border=0>';
contents+='<tr><td align=center>';
contents+='你要关闭我吗?<br>';
contents+='<img src=http://www.aspxclub.com/uploadfile/material/1/1281.gif onclick=self.close() alt="...关闭">';
contents+='<img src=http://www.aspxclub.com/uploadfile/material/1/1282.gif onclick=self.close() alt="全是关闭">';
contents+='</td></tr></table>';
showmodaldialog("about:"+contents+"","","dialogheight:50px;dialogwidth:250px;help:no;status:no")
document.write(contents);
</script>//
90.取第x,y的值
<button onclick="t1.rows[x].cells[y].innertext='guoguo'"></button>//
91.向新打开的网页上写内容
newwin=window.open('about:blank','','top=10');
newwin.document.write('');//
93.返回
javascript:history.go(-2);//
94.将页面上选中的内容复制到剪贴板
abcdefg
<input type='button'
onclick="window.clipboarddata.setdata('text',document.selection.createrange().text);" value='复制页面选中
的字符'>//
95.将页面上选中的内容复制到剪贴板
<input type="text" name="">kjhkjhkhkj<input type="button" onclick="document.execcommand('copy', 'false',
null);">////
96.鼠标移到下拉框时自动全部打开
<select onmouseover="javascript:this.size=this.length" onmouseout="javascript:this.size=1"></select>//
97.获得本机的文件
var fso = new activexobject("scripting.filesystemobject");
var f1 = fso.getfile("c:\\bsitcdata\\ejbhome.xml");
alert("file last modified: " + f1.datelastmodified); //
98.判断客户端是否是ie浏览器
因为 document.all 是 ie 的特有属性,所以通常用这个方法来判断客户端是否是ie浏览器 ,document.all?1:0;
99.创建新的下拉框选项
new option(text,value)这样的函数//
100.在页面上画柱状图
<style>
td{font-size:12px}
body{font-size:12px}
v\:*{behavior:url(#default#vml);} //这里声明了v作为vml公用变量
</style>
<script language="javascript">
mathstr=12;
document.write ("<v:rect fillcolor='red'
style='width:20;color:navy;height:"+5000/(1000/mathstr)+"'><br> %"+mathstr+"<br>4人<v:extrusion
backdepth='15pt' on='true'/></v:rect>")
</script>
<v:rect fillcolor='red' style='width:20;color:navy;height:200'><br>%12<br>4人<v:extrusion
backdepth='15pt' on='true'/></v:rect>
<v:rect fillcolor='yellow' style='width:20;color:navy;height:100'><br>%12<br>4人<v:extrusion
backdepth='15pt' on='true'/></v:rect>//
101.饼图
<style>
v\:* { behavior: url(#default#vml) }
o\:* { behavior: url(#default#vml) }
.shape { behavior: url(#default#vml) }
</style>
<script language="javascript">
function show(pie)
{
pie.strokecolor=pie.fillcolor;
pie.strokeweight=10;
div1.innerhtml="<font size=2 color=red> " + pie.id +"</font> <font size=2>" + pie.title + "</font>";
}
function hide(pie)
{
pie.strokecolor="white";
pie.strokeweight=1;
div1.innerhtml="";
}
</script>
</head>
<body>
<v:group style='width: 5cm; height: 5cm' coordorigin='0,0' coordsize='250,250'>
<v:shape id='asp技术' style='width:10;height:10;top:10;left:0' title='得票数:6 比例:40.00%'
onmouseover='javascript:show(this);' onmouseout='javascript:hide(this);' href='http://www.cnado.com'
coordsize='10,10' strokecolor='white' fillcolor='#ffff33'><v:path v='m 300,200 ae
300,200,200,150,0,9437184 xe'/></v:shape>
<v:shape id='php' style='width:10;height:10;top:10;left:0' title='得票数:1 比例:6.67%'
onmouseover='javascript:show(this);' onmouseout='javascript:hide(this);' href='http://www.cnado.com'
coordsize='10,10' strokecolor='white' fillcolor='#ff9933'><v:path v='m 300,200 ae
300,200,200,150,9437184,1572864 xe'/></v:shape>
<v:shape id='jsp' style='width:10;height:10;top:10;left:0' title='得票数:2 比例:13.33%'
onmouseover='javascript:show(this);' onmouseout='javascript:hide(this);' href='http://www.cnado.com'
coordsize='10,10' strokecolor='white' fillcolor='#3399ff'><v:path v='m 300,200 ae
300,200,200,150,11010048,3145728 xe'/></v:shape>
<v:shape id='c#写的.netweb程序' style='width:10;height:10;top:10;left:0' title='得票数:3 比例:20.00%'
onmouseover='javascript:show(this);' onmouseout='javascript:hide(this);' href='http://www.cnado.com'
coordsize='10,10' strokecolor='white' fillcolor='#99ff33'><v:path v='m 300,200 ae
300,200,200,150,14155776,4718592 xe'/></v:shape>
<v:shape id='vb.net写的.netweb程序' style='width:10;height:10;top:10;left:0' title='得票数:2 比例:13.33%'
onmouseover='javascript:show(this);' onmouseout='javascript:hide(this);' href='http://www.cnado.com'
coordsize='10,10' strokecolor='white' fillcolor='#ff6600'><v:path v='m 300,200 ae
300,200,200,150,18874368,3145728 xe'/></v:shape>
<v:shape id='xml技术' style='width:10;height:10;top:10;left:0' title='得票数:1 比例:6.67%'
onmouseover='javascript:show(this);' onmouseout='javascript:hide(this);' href='http://www.cnado.com'
coordsize='10,10' strokecolor='white' fillcolor='#ff99ff'><v:path v='m 300,200 ae
300,200,200,150,22020096,1572864 xe'/></v:shape>
</v:group>
<v:group style='width: 6cm; height: 6cm' coordorigin='0,0' coordsize='250,250'>
<v:rect style='height:10;width:15;top:0;left:10' fillcolor='#ffff33'/>
<v:rect style='height:28;width:100;top:0;left:30' stroked='false'><v:textbox
style='fontsize:2'>asp技术</v:textbox/></v:rect>
<v:rect style='height:10;width:15;top:30;left:10' fillcolor='#ff9933'/>
<v:rect style='height:28;width:100;top:30;left:30' stroked='false'><v:textbox
style='fontsize:2'>php</v:textbox/></v:rect>
<v:rect style='height:10;width:15;top:60;left:10' fillcolor='#3399ff'/>
<v:rect style='height:28;width:100;top:60;left:30' stroked='false'><v:textbox
style='fontsize:2'>jsp</v:textbox/></v:rect>
<v:rect style='height:10;width:15;top:90;left:10' fillcolor='#99ff33'/>
<v:rect style='height:28;width:100;top:90;left:30' stroked='false'><v:textbox
style='fontsize:2'>c#写的.netweb程序</v:textbox/></v:rect>
<v:rect style='height:10;width:15;top:120;left:10' fillcolor='#ff6600'/>
<v:rect style='height:28;width:100;top:120;left:30' stroked='false'><v:textbox style='fontsize:2'>vb.net
写的.netweb程序</v:textbox/></v:rect>
<v:rect style='height:10;width:15;top:150;left:10' fillcolor='#ff99ff'/>
<v:rect style='height:28;width:100;top:150;left:30' stroked='false'><v:textbox style='fontsize:2'>xml技术
</v:textbox/></v:rect>
</v:group>
<div style="position: absolute; left: 10; top: 10; width: 760; height:16">
<table border="1" cellpadding="2" cellspacing="2" cellpadding="0" cellspacing="0"
style="border-collapse: collapse" bordercolor="#cccccc" width="100%" id="table1">
<tr>
<td width="100%" id=div1> </td>
</tr>
</table>
</div>//
102.是一个特殊的容器,想装个网页都行
<button><iframe src=http://blog.csdn.net/lxs5i5j/archive/2007/01/22/"http://www.google.com/"></iframe></button>//button
103.外部的html代码
event.srcelement.outerhtml//
104.标识当前的ie事件的触发器
event.srcelement和event.keycode//
105.事件类型
event.type//
106.动态改变类型
<style>
.overnone { border-width:0;background-color:darkblue;cursor:default;color:gold;width:115}
.outnone {border-width:0;background-color:white;cursor:default;width:115}
</style>
<input class=outnone onmouseover=this.classname='overnone' >//
107.页面翻转
<html dir=rtl></html>//
onblur:当失去输入焦点后产生该事件
onfocus:当输入获得焦点后,产生该文件
onchange:当文字值改变时,产生该事件
onselect:当文字加亮后,产生该文件
<input type="text" value="郭强" onfocus="if(value=='郭强') {value=''}" onblur="if
(value=='') {value='郭强'}">点击时文字消失,失去焦点时文字再出现
2.网页按钮的特殊颜色
<input type=button name="submit1" value="郭强" size=10 class=s02
style="background-color:rgb(235,207,22)">
3.鼠标移入移出时颜色变化
<input type="submit" value="找吧" name="b1" onmouseout=this.style.color="blue"
onmouseover=this.style.color="red" class="button">
4.平面按钮
<input type=submit value=订阅 style="border:1px solid :#666666; height:17px; width:25pt; font-size:9pt;
background-color: #e8e8ff; color:#666666" name="submit">
5.按钮颜色变化
<input type=text name="nick" style="border:1px solid #666666; font-size:9pt; height:17px;
background-color: #f4f4ff; color:#ff6600" size="15" maxlength="16">
6.平面输入框
<input type="text" name="t1" size="20" style="border-style: solid; border-width: 1">
7.使窗口变成指定的大小
<script>
window.resizeto(300,283);
</script>
8.使文字上下滚动
<marquee direction=up scrollamount=1 scrolldelay=100 onmouseover='this.stop()' onmouseout='this.start()'
height=60>
<!-- head_scrolltext -->
<tr>
<td>
*
</table> <!-- end head_scrolltext -->
</marquee>
9.状态栏显示该页状态
<base onmouseover="window.status='网站建设 http://www.webmake.cn/' ;return true">
10.可以点击文字实现radio选项的选定
<br>
<input type="radio" name="regtype" value="a03" id="a03">
<label for="a03"> 情侣 : 一次注册两个帐户</label> <br>
11.可以在文字域的font写onclick事件
12.打印
<a href='javascript:window.print ()'> </a>打印网页
13.线型输入框
<input type="text" name="key" size="12" value="关键字" onfocus=this.select() onmouseover=this.focus()
class="line">
14.显示文档最后修改日期
<script language=javascript>
function hi(str)
{
document.write(document.lastmodified)
alert("hi"+str+"!")
}
</script>
15.可以在鼠标移到文字上时就触发事件
<html>
<head>
<script language="livescript">
<!-- hiding
function hello() {
alert("哈罗!");
}
</script>
</head>
<body>
<a href="" onmouseover="hello()">link</a>
</body>
</html>
16.可以根据网页上的选项来确定页面颜色
<html>
<head>
<title>background.html</title>
</head>
<script>
<!--
function bgchange(selobj) {
newcolor = selobj.options[selobj.selectedindex].text;
document.bgcolor = newcolor;
selobj.selectedindex = -1;
}
//-->
</script>
<body style="font-family:arial">
<b>changing background colors</b>
<br>
<form>
<select size="8" onchange="bgchange(this);">
<option>red
<option>orange
<option>yellow
<option>green
<option>blue
<option>indigo
<option>violet
<option>white
<option>pink
</select>
</form>
</body>
</html>
17.将按钮的特征改变
<style type="text/css">
<!--
.style1 { font-size: 12px; background: #ccccff; border-width: thin thin thin thin; border-color: #ccccff
#cccccc #cccccc #ccccff}
.style2 { font-size: 12px; font-weight: bold; background: #ccffcc; border-width: thin medium medium thin;
border-color: #ccff99 #999999 #999999 #ccff99}
-->
</style>
本例按钮的代码如下:
<input type="submit" name="submit" value="提 交" onmouseover="this.classname='style2'"
onmouseout="this.classname='style1'" class="style1">
18.改变按钮的图片.
<style type="text/css">
<!--
.style3 { font-size: 12px; background: url(image/buttonbg1.gif); border: 0px; width: 60px; height: 22px}
.style4 { font-size: 12px; font-weight: bold; background: url(image/buttonbg2.gif); border: 0px 0; width:
60px; height: 22px}
-->
</style>
本例的按钮代码如下:
<input type="submit" name="submit2" value="提 交" onmouseover="this.classname='style4'"
onmouseout="this.classname='style3'" class="style3">
19.打印页面
<div align="center"><a class=content href="javascript:doprint();">打印本稿</a></div>
20.可以直接写html语言
document.write("");
21.改变下拉框的颜色
<select name="classid"
onchange="changelocation(document.myform.classid.options[document.myform.classid.selectedindex].value)"
size="1" style="color:#008080;font-size: 9pt">
22.转至目标url
window.location=http://blog.csdn.net/lxs5i5j/archive/2007/01/22/"http://guoguo"
23.传递该object的form
updatesn('guoqiang99267',this.form)
function updatesn(strvalue,strform)
{
strform.signinname.value = strvalue;
return false;
}
24.文字标签
<label for="altname4"><input name="altname" type="radio" tabindex="931" id="altname4"
>guoqiang99859</label>
25.layer2为组件的id,可以控制组件是否可见
document.all.item('layer2').style.display = "block";
document.all.item('layer2').style.display = "none";//
26.将页面加入favorite中
<script language=javascript>
<!--
function addme(){
url = http://blog.csdn.net/lxs5i5j/archive/2007/01/22/"http://your.site.address"; //你自己的主页地址
title = "your site name"; //你自己的主页名称
window.external.addfavorite(url,title);
-->
</script>//
27.过10秒自动关闭页面
< script language="javascript" >
function closeit() {
settimeout("self.close()",10000)
}
< /script >
28.可以比较字符的大小
char=post.charat(i);
if(!('0'<=char&&char<='9'))
29.将字符转化为数字
month = parseint(char)
30.点击value非空的选项时转向指定连接
<select onchange='if(this.value!="")window.open(this.value)' class="textinput">
<option selected>主办单位</option>
<option>-----------------</option>
<option value=http://blog.csdn.net/lxs5i5j/archive/2007/01/22/"http://www.bjd.com.cn/">北京日报</option>
<option value=http://blog.csdn.net/lxs5i5j/archive/2007/01/22/"http://www.ben.com.cn/">北京晚报</option>
</select>
31.改变背景颜色
<td width=* class=dp bgcolor=#fafbfc onmouseover="this.bgcolor='#ffffff';"
onmouseout="this.bgcolor='#fafbfc';">
32.改变文字输入框的背景颜色
<style>
.input2 {background-image: url('../images/inputbg.gif'); font-size: 12px; background-color:
#d0dabb;border-top-width:1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px}
</style>
<input name=content type=text size="47" class="input2" maxlength="50">
33.改变水平线的特征
<hr size="0" noshade color="#c0c0c0">
34.传递参数的方式
<a href="vote.asp?curpage=8&id=3488">8</a>
35.页内跳转
<a href="#1">1</a>
<a href="#2">2</a>
<a href="#3">3</a>
<a href="#4">4</a>
<a href="#5">5</a>
<a href="#6">6</a>
<a href="#7">7</a>
<a name="1">dfdf</a>
<a name="2">dfdf</a>//
36.两个按键一起按下
if(event.ctrlkey && window.event.keycode==13)//
37.刷新页面
javascript:this.location.reload()//
38.将网页的按钮使能
<script language="javascript">
function haha()
{
for(var i=0;i<document.form1.elements.length;i++)
{
if(document.form1.elements[i].name.indexof("bb")!=-1)
document.form1.elements[i].disabled=!document.form1.elements[i].disabled;
}
}
</script>
<body><form name=form1>
<input type="button" name="aa " value=cindy onclick=haha()>
<input type="button" name="bb " value=guoguo>
<input type="button" name="bb " value=guoguo>
39.文字移动
<marquee scrollamount=3 onmouseover=this.stop(); onmouseout=this.start();>
40.双击网页自动跑
<script language="javascript">
var currentpos,timer;
function initialize()
{
timer=setinterval("scrollwindow()",1);
}
function sc()
{
clearinterval(timer);
}
function scrollwindow()
{
currentpos=document.body.scrolltop;
window.scroll(0,++currentpos);
if (currentpos != document.body.scrolltop)
sc();
}
document.onmousedown=sc
document.ondblclick=initialize
</script>//
41.后退
<input type="button" onclick=window.history.back() value=back>
42.前进
<input type="button" onclick=window.history.forward() value=forward>
43.刷新
<input type="button" onclick=document.location.reload() value=reload>
44.转向指定网页
document.location=http://blog.csdn.net/lxs5i5j/archive/2007/01/22/"http://ww"或者document.location.assign(http://blog.csdn.net/lxs5i5j/archive/2007/01/22/"http://guoguo.com")
45.在网页上显示实时时间
<script language="javascript">
var clock_id;
window.onload=function()
{
clock_id=setinterval("document.form1.txtclock.value=(new date);",1000)
}
</script>//
46.可以下载文件
document.location.href="目标文件"//
47.连接数据库
import java.sql.*;
string mydbdriver="sun.jdbc.odbc.jdbcodbcdriver";
class.forname(mydbdriver);
connection conn=drivermanager.getconnection("jdbc:odbc:firm","username","password");
statement stmt=conn.createstatement();
resultset rs=stmt.executequery(sql);
rs.getstring("column1");//
48.可以直接在页面“div”内写下所需内容
<input type="button" onclick="a1.innerhtml='<font color=red>*</font>'">
<div id=a1></div>//
49.可以改变页面上的连接的格式,使其为双线
<style>
a:link {text-decoration: none; color:#0000ff; font-family: 宋体}
a:visited {text-decoration: none; color: #0000ff; font-family: 宋体}
a:hover {text-decoration: underline overline; color: ff0000}
</style>
<style>
a:link {text-decoration: none; color:#0000ff; font-family: 宋体}
a:visited {text-decoration: none; color: #0000ff; font-family: 宋体}
a:hover {text-decoration: underline overline line-through; color: ff0000}
th{font-size: 9pt}
td{font-size: 9pt}
body {scrollbar-face-color: #a9d46d; scrollbar-highlight-color: #e7e7e7;scrollbar-shadow-color:#e7e7e7;
scrollbar-3dlight-color: #000000; line-height: 15pt; scrollbar-arrow-color: #ffffff;
scrollbar-track-color: #e7e7e7;}
input{border-top-width: 1px; padding-right: 1px; padding-left: 1px; border-left-width: 1px; font-size:
9pt; border-left-color: #cccccc;
border-bottom-width: 1px; border-bottom-color: #cccccc; padding-bottom: 1px; border-top-color: #cccccc;
padding-top: 1px; height: 18px; border-right-width: 1px; border-right-color: #cccccc}
div,form ,option,p,td,br{font-family: 宋体; font-size: 9pt}
textarea, select {border-width: 1; border-color: #000000; background-color: #efefef; font-family: 宋体;
font-size: 9pt; font-style: bold;}
.text { font-family: "宋体"; font-size: 9pt; color: #003300; border: #006600 solid; border-width: 1px 1px
1px 1px}
</style>完整的css
50.新建frame
<a
href="javascript:newframe('http://www.163.net/help/a_little/index.html','http://www.163.net/help/a_little
/a_13.html')"><img alt=帮助 border=0 src=http://blog.csdn.net/lxs5i5j/archive/2007/01/22/"http://bjpic.163.net/images/mail/button-help.gif"></a>
51.向文件中写内容
<%@ page import="java.io.*" %>
<%
string str = "print me";
//always give the path from root. this way it almost always works.
string nameoftextfile = "/usr/anil/imp.txt";
try
{
printwriter pw = new printwriter(new fileoutputstream(nameoftextfile));
pw.println(str);
//clean up
pw.close();
}
catch(ioexception e)
{
out.println(e.getmessage());
}
%>
52.先读文件再写文件
<%@ page language = "java" %>
<%@ page contenttype = "text/html; charset=gb2312" %>
<%@ page import ="java.util.*" %>
<%@ page import ="java.lang.*" %>
<%@ page import ="javax.servlet.*" %>
<%@ page import ="javax.servlet.jsp.*" %>
<%@ page import ="javax.servlet.http.*" %>
<%@ page import="java.io.*" %>
eryrytry
<%
int count=0;
fileinputstream fi =new fileinputstream ("count.txt");
objectinputstream si= new objectinputstream (fi);
count =si.readint();
count++;
out.print(count);
si.close();
fileoutputstream fo =new fileoutputstream ("count.txt");
objectoutputstream so= new objectoutputstream (fo);
so.writeint(count);
so.close();
%>
53.直线型输入框
<input name=password size=10 type=password style="border-left-width: 0; border-right-width: 0;
border-top-width: 0; border-bottom-style: solid; border-bottom-width: 1; background-color: #9ceb9c">
54.可以将背景改为按钮性状,通过改变css改变属性
<td width="65" align="center" bgcolor="#e0e0e0" onmouseover=this.classname='mouseoverbt';
onmouseout=this.classname='mouseout';><a href="tm.asp?classid=76"><font
color="#000000">录音笔</font></a></td>
<style>
.mouseoverbt
{
background-image: url(file:///c|/"><input type="submit" value="c:\ drive"></form>//
85.当前屏幕的分辨率
screen.width、screen.height//
86.设置表格中的内容
tbl.rows[0].cells[1].innertext=document.form.text1.value;//
87.本地快捷键
<p><a href=http://blog.csdn.net/lxs5i5j/archive/2007/01/22/"file:///::{208d2c60-3aea-1069-a2d7-08002b30309d}" target="_blank">网上邻居</a></p>
<p><a href=http://blog.csdn.net/lxs5i5j/archive/2007/01/22/"file:///::{20d04fe0-3aea-1069-a2d8-08002b30309d}\d:\web" target="_blank">我的电脑</a></p>
<p><a href=http://blog.csdn.net/lxs5i5j/archive/2007/01/22/"file:///::{450d8fba-ad25-11d0-98a8-0800361b1103}" target="_blank">我的文档</a></p>
<p><a href=http://blog.csdn.net/lxs5i5j/archive/2007/01/22/"file:///::{645ff040-5081-101b-9f08-00aa002f954e}" target="_blank">回收站</a></p>
<p><a href=http://blog.csdn.net/lxs5i5j/archive/2007/01/22/"file:///::{20d04fe0-3aea-1069-a2d8-08002b30309d}\::{21ec2020-3aea-1069-a2dd-08002b30309d}"
target="_blank">控制面板</a></p>
<p><a href=http://blog.csdn.net/lxs5i5j/archive/2007/01/22/"file:///::{7007acc7-3202-11d1-aad2-00805fc1270e}">拨号网络</a>(windows 2000)</p>
88.ie菜单
<button onclick="min.click()"><font face="webdings">0</font></button>//改变按钮上的图片
<input type=button onclick="document.execcommand('createlink','true','true')"> //创建新连接
<input type=button onclick="document.execcommand('print','true','true')"> //打印
<input type=button onclick="document.execcommand('saveas','true','网站制作.htm')">//另存为htm
<input type=button onclick="document.execcommand('saveas','true','网站制作.txt')">//另存为txt
document.execcommand("saveas")//保存为
document.execcommand('undo')//撤销上一次操作
89.web对话框
<script>
var contents='<style>body,td{font:menu}img{cursor:hand}</style>';
contents+='<title>你要关闭我吗</title>';
contents+='<body bgcolor=menu>';
contents+='<table width=100% height=100% border=0>';
contents+='<tr><td align=center>';
contents+='你要关闭我吗?<br>';
contents+='<img src=http://www.aspxclub.com/uploadfile/material/1/1281.gif onclick=self.close() alt="...关闭">';
contents+='<img src=http://www.aspxclub.com/uploadfile/material/1/1282.gif onclick=self.close() alt="全是关闭">';
contents+='</td></tr></table>';
showmodaldialog("about:"+contents+"","","dialogheight:50px;dialogwidth:250px;help:no;status:no")
document.write(contents);
</script>//
90.取第x,y的值
<button onclick="t1.rows[x].cells[y].innertext='guoguo'"></button>//
91.向新打开的网页上写内容
newwin=window.open('about:blank','','top=10');
newwin.document.write('');//
93.返回
javascript:history.go(-2);//
94.将页面上选中的内容复制到剪贴板
abcdefg
<input type='button'
onclick="window.clipboarddata.setdata('text',document.selection.createrange().text);" value='复制页面选中
的字符'>//
95.将页面上选中的内容复制到剪贴板
<input type="text" name="">kjhkjhkhkj<input type="button" onclick="document.execcommand('copy', 'false',
null);">////
96.鼠标移到下拉框时自动全部打开
<select onmouseover="javascript:this.size=this.length" onmouseout="javascript:this.size=1"></select>//
97.获得本机的文件
var fso = new activexobject("scripting.filesystemobject");
var f1 = fso.getfile("c:\\bsitcdata\\ejbhome.xml");
alert("file last modified: " + f1.datelastmodified); //
98.判断客户端是否是ie浏览器
因为 document.all 是 ie 的特有属性,所以通常用这个方法来判断客户端是否是ie浏览器 ,document.all?1:0;
99.创建新的下拉框选项
new option(text,value)这样的函数//
100.在页面上画柱状图
<style>
td{font-size:12px}
body{font-size:12px}
v\:*{behavior:url(#default#vml);} //这里声明了v作为vml公用变量
</style>
<script language="javascript">
mathstr=12;
document.write ("<v:rect fillcolor='red'
style='width:20;color:navy;height:"+5000/(1000/mathstr)+"'><br> %"+mathstr+"<br>4人<v:extrusion
backdepth='15pt' on='true'/></v:rect>")
</script>
<v:rect fillcolor='red' style='width:20;color:navy;height:200'><br>%12<br>4人<v:extrusion
backdepth='15pt' on='true'/></v:rect>
<v:rect fillcolor='yellow' style='width:20;color:navy;height:100'><br>%12<br>4人<v:extrusion
backdepth='15pt' on='true'/></v:rect>//
101.饼图
<style>
v\:* { behavior: url(#default#vml) }
o\:* { behavior: url(#default#vml) }
.shape { behavior: url(#default#vml) }
</style>
<script language="javascript">
function show(pie)
{
pie.strokecolor=pie.fillcolor;
pie.strokeweight=10;
div1.innerhtml="<font size=2 color=red> " + pie.id +"</font> <font size=2>" + pie.title + "</font>";
}
function hide(pie)
{
pie.strokecolor="white";
pie.strokeweight=1;
div1.innerhtml="";
}
</script>
</head>
<body>
<v:group style='width: 5cm; height: 5cm' coordorigin='0,0' coordsize='250,250'>
<v:shape id='asp技术' style='width:10;height:10;top:10;left:0' title='得票数:6 比例:40.00%'
onmouseover='javascript:show(this);' onmouseout='javascript:hide(this);' href='http://www.cnado.com'
coordsize='10,10' strokecolor='white' fillcolor='#ffff33'><v:path v='m 300,200 ae
300,200,200,150,0,9437184 xe'/></v:shape>
<v:shape id='php' style='width:10;height:10;top:10;left:0' title='得票数:1 比例:6.67%'
onmouseover='javascript:show(this);' onmouseout='javascript:hide(this);' href='http://www.cnado.com'
coordsize='10,10' strokecolor='white' fillcolor='#ff9933'><v:path v='m 300,200 ae
300,200,200,150,9437184,1572864 xe'/></v:shape>
<v:shape id='jsp' style='width:10;height:10;top:10;left:0' title='得票数:2 比例:13.33%'
onmouseover='javascript:show(this);' onmouseout='javascript:hide(this);' href='http://www.cnado.com'
coordsize='10,10' strokecolor='white' fillcolor='#3399ff'><v:path v='m 300,200 ae
300,200,200,150,11010048,3145728 xe'/></v:shape>
<v:shape id='c#写的.netweb程序' style='width:10;height:10;top:10;left:0' title='得票数:3 比例:20.00%'
onmouseover='javascript:show(this);' onmouseout='javascript:hide(this);' href='http://www.cnado.com'
coordsize='10,10' strokecolor='white' fillcolor='#99ff33'><v:path v='m 300,200 ae
300,200,200,150,14155776,4718592 xe'/></v:shape>
<v:shape id='vb.net写的.netweb程序' style='width:10;height:10;top:10;left:0' title='得票数:2 比例:13.33%'
onmouseover='javascript:show(this);' onmouseout='javascript:hide(this);' href='http://www.cnado.com'
coordsize='10,10' strokecolor='white' fillcolor='#ff6600'><v:path v='m 300,200 ae
300,200,200,150,18874368,3145728 xe'/></v:shape>
<v:shape id='xml技术' style='width:10;height:10;top:10;left:0' title='得票数:1 比例:6.67%'
onmouseover='javascript:show(this);' onmouseout='javascript:hide(this);' href='http://www.cnado.com'
coordsize='10,10' strokecolor='white' fillcolor='#ff99ff'><v:path v='m 300,200 ae
300,200,200,150,22020096,1572864 xe'/></v:shape>
</v:group>
<v:group style='width: 6cm; height: 6cm' coordorigin='0,0' coordsize='250,250'>
<v:rect style='height:10;width:15;top:0;left:10' fillcolor='#ffff33'/>
<v:rect style='height:28;width:100;top:0;left:30' stroked='false'><v:textbox
style='fontsize:2'>asp技术</v:textbox/></v:rect>
<v:rect style='height:10;width:15;top:30;left:10' fillcolor='#ff9933'/>
<v:rect style='height:28;width:100;top:30;left:30' stroked='false'><v:textbox
style='fontsize:2'>php</v:textbox/></v:rect>
<v:rect style='height:10;width:15;top:60;left:10' fillcolor='#3399ff'/>
<v:rect style='height:28;width:100;top:60;left:30' stroked='false'><v:textbox
style='fontsize:2'>jsp</v:textbox/></v:rect>
<v:rect style='height:10;width:15;top:90;left:10' fillcolor='#99ff33'/>
<v:rect style='height:28;width:100;top:90;left:30' stroked='false'><v:textbox
style='fontsize:2'>c#写的.netweb程序</v:textbox/></v:rect>
<v:rect style='height:10;width:15;top:120;left:10' fillcolor='#ff6600'/>
<v:rect style='height:28;width:100;top:120;left:30' stroked='false'><v:textbox style='fontsize:2'>vb.net
写的.netweb程序</v:textbox/></v:rect>
<v:rect style='height:10;width:15;top:150;left:10' fillcolor='#ff99ff'/>
<v:rect style='height:28;width:100;top:150;left:30' stroked='false'><v:textbox style='fontsize:2'>xml技术
</v:textbox/></v:rect>
</v:group>
<div style="position: absolute; left: 10; top: 10; width: 760; height:16">
<table border="1" cellpadding="2" cellspacing="2" cellpadding="0" cellspacing="0"
style="border-collapse: collapse" bordercolor="#cccccc" width="100%" id="table1">
<tr>
<td width="100%" id=div1> </td>
</tr>
</table>
</div>//
102.是一个特殊的容器,想装个网页都行
<button><iframe src=http://blog.csdn.net/lxs5i5j/archive/2007/01/22/"http://www.google.com/"></iframe></button>//button
103.外部的html代码
event.srcelement.outerhtml//
104.标识当前的ie事件的触发器
event.srcelement和event.keycode//
105.事件类型
event.type//
106.动态改变类型
<style>
.overnone { border-width:0;background-color:darkblue;cursor:default;color:gold;width:115}
.outnone {border-width:0;background-color:white;cursor:default;width:115}
</style>
<input class=outnone onmouseover=this.classname='overnone' >//
107.页面翻转
<html dir=rtl></html>//
上一篇: 产妇金银花能吃吗
下一篇: 月子汤怎么做好吃又营养呢