| 经典Transact-SQL语句 -SQL语句的构造实在是太有趣了,让我们大家一起收集、分享和学习 语句区域 1、delete table1 from (select * from table2) as t2 where table1.id=t2.id 2、truncate table table1 (不在事务日志中做记录,比delete table快,但不能激活触发器) 3、update table1 set column=column+1 where id=(select id from table2) 4、update table1 set column=column+1 from table1,table2 where table1.id=table2.id 5、select top n [Percent] * from table1 '输出百分比记录 6、select id,column1 * column2 as column from table1 7、select * from table1 where column1 like 'SQL#_G_O' escape '#' 8、select * from table1 group by column1 with rollup '只返回最高组数据 ----------------------------------------- 杂类区域 [删除当前游标记录]:delete from table1 where current of dinof_cursor [清楚事务日志]:backup log dbname with truncate_only '暂不知更新多少数据会回滚 [设定一次读取容量]:set @@textsize '最大字节数2,147,483,647 SQL常用命令使用方法: SQL常用命令使用方法: (1) 数据记录筛选: sql="select * from 数据表 where 字段名=字段值 order by 字段名 " sql="select * from 数据表 where 字段名 like ‘%字段值%‘ order by 字段名 " sql="select top 10 * from 数据表 where 字段名 order by 字段名 " sql="select * from 数据表 where 字段名 in (‘值1‘,‘值2‘,‘值3‘)" sql="select * from 数据表 where 字段名 between 值1 and 值2" (2) 更新数据记录: sql="update 数据表 set 字段名=字段值 where 条件表达式" sql="update 数据表 set 字段1=值1,字段2=值2 …… 字段n=值n where 条件表达式" (3) 删除数据记录: sql="delete from 数据表 where 条件表达式" sql="delete from 数据表" (将数据表所有记录删除) (4) 添加数据记录: sql="insert into 数据表 (字段1,字段2,字段3 …) valuess (值1,值2,值3 …)" sql="insert into 目标数据表 select * from 源数据表" (把源数据表的记录添加到目标数据表) (5) 数据记录统计函数: AVG(字段名) 得出一个表格栏平均值 COUNT(*|字段名) 对数据行数的统计或对某一栏有值的数据行数统计 MAX(字段名) 取得一个表格栏最大的值 MIN(字段名) 取得一个表格栏最小的值 SUM(字段名) 把数据栏的值相加 引用以上函数的方法: sql="select sum(字段名) as 别名 from 数据表 where 条件表达式" set rs=conn.execute(sql) 用 rs("别名") 获取统的计值,其它函数运用同上。 (6) 数据表的建立和删除: CREATE TABLE 数据表名称(字段1 类型1(长度),字段2 类型2(长度) …… ) 例:CREATE TABLE tab01(name varchar(50),datetime default now()) DROP TABLE 数据表名称 (永久性删除一个数据表) 4. 记录集对象的方法: rs.movenext 将记录指针从当前的位置向下移一行 rs.moveprevious 将记录指针从当前的位置向上移一行 rs.movefirst 将记录指针移到数据表第一行 rs.movelast 将记录指针移到数据表最后一行 rs.absoluteposition=N 将记录指针移到数据表第N行 rs.absolutepage=N 将记录指针移到第N页的第一行 rs.pagesize=N 设置每页为N条记录 rs.pagecount 根据 pagesize 的设置返回总页数 rs.recordcount 返回记录总数 rs.bof 返回记录指针是否超出数据表首端,true表示是,false为否 rs.eof 返回记录指针是否超出数据表末端,true表示是,false为否 rs.delete 删除当前记录,但记录指针不会向下移动 rs.addnew 添加记录到数据表末端 rs.update 更新数据表记录 判断所填数据是数字型 if not isNumeric(request("字段名称")) then response.write "不是数字" else response.write "数字" end if ------------------------------------------------------------------------ ASP和SQL结合处理时间小解 在开发数据库应用中,经常会遇到处理时间的问题,如查询指定时间的记录等。下面就这些常见的问题,结合自己的一些经验,和大家探讨一下这类问题。 首先介绍一下,SQL Server里处理时间的几个主要函数的用法: getdate()函数:取得系统当前的日期和时间。返回值为datetime类型的。 用法:getdate() 例子: select getdate() as dte,dateadd(day,-1,getdate()) as nowdat 输出结果: dte nowdat 1999-11-21 19:13:10.083 1999-11-20 19:13:10.083 (1 row(s) affected) datepart()函数:以整数的形式返回时间的指定部分。 用法:datepart(datepart,date) 参数说明:datepart时要返回的时间的部分,常用取值year、month、day、hour、minute。 date是所指定的时间。 例子: SELECT DATEPART(month, GETDATE()) AS 'Month Number' 输出结果: Month Number 11 (1 row(s) affected) dateadd()函数:通过给指定的时间的指定部分加上一个整数值以返回一个新时间值。 用法:dateadd(datepart,number,date) 参数说明:datepart(同上) date(同上) number要增加的值,整型,可正可负,正值返回date之后的时间值,负值返回date 之前的时间值 例子: select getdate() as today select dateadd(day,-1,getdate()) select dateadd(day,1,getdate()) 输出: today 1999-11-21 19:42:41.410 (1 row(s) affected) yesterday 1999-11-20 19:42:41.410 (1 row(s) affected) tomorrow 1999-11-22 19:42:41.410 (1 row(s) affected) datediff()函数:返回两个时间以指定时间部分来计算的差值。返回整数值。如1991-6-12和1991-6-21之间以天 来算相差9天,1998-6-12和1999-6-23按年算相差1年,1999-12-1和1999-3-12按月算相差9个月 用法:datediff(darepart,date1,date2) 参数说明:datepart(同上) date1、date2(同上date) 例子: select datediff(month,'1991-6-12','1992-6-21') as a 输出: a 12 (1 row(s) affected) SQL Server对select语句返回多条记录给变量赋值时的处理情况 declare @user nvarchar(20) select @user='user1' use countme /*判断用户是否存在*/ declare @userweek int select @userweek=[week] from base where userid=@user select @@rowcount if @@rowcount=0 return select @userweek 最后的@userweek打印出来的结果就是记录用户名为user1的week字段的值 而当我们用下面的语句选择所有记录时(没有where限制) declare @user nvarchar(20) select @user='user1' use countme /*判断用户是否存在*/ declare @userweek int select @userweek=[week] from base select @@rowcount if @@rowcount=0 return select @userweek 最后@userweek打印出来的值是返回的所有记录中排名最后一条记录的week字段值 SQL语句简介-给初学者 运用数据库管理是ASP的最引以自豪的功能正是由于它在运行数据库上的强大的优势,才使得的人们相信CGI是可以代替的,当然要在数据库上做文章,不知道SQL是不可能的,在ASP中无论何时访问一个数据库,都要用SQL语句,因此掌握好SQL对ASP编程是非常重要的(不好了...臭鸡蛋过来了.....成龙赶紧闪........) 在ASP中我们最最常用的是SQL的数据查询语言和数据操作语言 那就先介绍数据查询吧 1.一般的数据查询的格式如下:(对单个表的查询操作) select 字段 from 表 where 查询条件 举例说明:我从student表中取出name字段为"成龙"的学生,显示的时候只显示name字段,可以用如下语句: select name from student where name='成龙' 2.操作多个表就显得稍微麻烦了,声名:操作多个表的时候一定要写出各个表的关联的字段,否则,取出多个表的记录的时候,将以排列组合的方式显示的,这样的查询在大多数的情况下是没有任何意义的,除非你刻意去这样做. 举例:数据库pubs中有三个表titleauthor,titles 和authors,titleauthor是用来将titles和authors表关联在一起的,可以写如下的查询语句: select au_name,title from author where authors.au_id=titles_id and titles.title_id=titleauthor.title_id 如果还有别的约束条件可以继续添加and或者or语句,如果查询操作的表是2个,而事先知道2个表中的字段是"多对多"的关系,就得用第3个表来关联了,如果2个表只存在"一对一"或者"一对多"的关系,可以利用公共字段对他们进行关联! 大家好我是成龙,上次介绍完了SQL语句的查询,这次该介绍SQL语句的操作了 其实操作语言也不难,包括insert,update,delete分别对表中的数据进行添加,修改和删除 1.插入数据语法如下: insert into mytable(mycolumn) values('somevalue') 举例说明一个student表有中的两个字段name和sex要插入数据记录为"成龙""男性" insert into student(name,sex) values('成龙','男性') 2.删除记录的语法如下: delete from mytable where some_lolunm='somevalue' 举例说明:将student表中name字段为"成龙"的记录删除 delete from student where name='成龙' 3.更新记录语法如下: update mytable set first_colum='some_value' where second_cloum='someother_value' 举例说明:将student 表中name字段为"成龙"的记录中的sex字段中的"男性"改为"男"(前提条件:没有把这个记录删除!) update student set sex='男' where name='成龙' 总结:SQL是一门非常强大的面向集合的数据库语言,想将它灵活运用并不是一件容易的事,需要你在以后的日子里不断的摸索推敲,当然,运用在ASP中的SQL语句都是相对简单的. 另外,还有关于SQL的5种集合函数,在这里就不介绍了,有兴趣者可以去看一点关于这方面的书,我想对于你学习ASP肯定是有帮助的 -------------------------------------------------------------------------- ASP与数据库应用 一般来说,一个真正的、完整的站点是离不开数据库的,因为实际应用中,需要保存的数据很多,而且这些数据之间往往还有关联,利用数据库来管理这些数据,可以很方便的查询和更新。数据库有很多种,如:Fox 数据库(.dbf)、Access 数据库(.mdb)、Informix、Oracle 和 SQL Server 等等,在这里,我将以 Microsoft Access 数据库为例来说明ASP是如何访问数据库的。 常用数据库语句 1.SELECT 语句:命令数据库引擎从数据库里返回信息,作为一组记录。 2.INSERT INTO 语句:添加一个或多个记录至一个表。 3.UPDATE 语句:创建更新查询来改变基于特定准则的指定表中的字段值。 4.DELETE 语句:创建一个删除查询把记录从 FROM 子句列出并符合 WHERE 子句的一个或更多的表中清除。 5.EXECUTE 语句:用于激活 PROCEDURE(过程) 用 ASP 来做一个自己的通讯录练练手吧…… 一、建立数据库: 用 Microsoft Access 建立一个名为 data.mdb 的空数据库,使用设计器创建一个新表。输入以下几个字段: 字段名称 数据类型 说明 其它 ID 自动编号 数据标识 字段大小:长整型 新值:递增 索引:有(无重复) username 文本 姓名 缺省值 usermail 文本 E-mail 缺省值 view 数字 查看次数 字段大小:长整型 默认值:0 索引:无 indate 时间日期 加入时间 缺省值 保存为 data.mdb 文件,为了便于说明,只是做了一个比较简单的库。 二、连接数据库 方法1: Set conn = Server.CreateObject("ADODB.Connection") conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq="&Server.MapPath("data.mdb") 方法2: Set conn = Server.CreateObject("ADODB.Connection") conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.MapPath("data.mdb") 注意:一个页面中,只要连接一次就可以了,数据库使用完后要及时关闭连接。 conn.Close Set conn = Nothing 三、添加新记录到数据库 Set conn = Server.CreateObject("ADODB.Connection") conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq="&Server.MapPath("data.mdb") username = "风云突变" usermail = "fytb@163.com" indate = Now() sql = "insert into data (username,usermail,indata) values('"&username&"','"&usermail&"','"&indate&"')" conn.Execute(sql) conn.Close Set conn = Nothing 说明:建立数据库连接;通过表单获取姓名、E-mail 字符串,Now()获取当前时间日期;使用 insert into 语句添加新记录;conn.Execute 来执行;最后关闭。 四、选择数据库里的记录 1.选择所有记录的字段(按记录倒序排序):sql = "select * from data order by ID desc" 2.选择所有记录的姓名和E-mail字段(不排序):sql = "select username,usermail from data" 3.选择姓名为“风云突变”的所有记录:sql = "select * from data where username='"风云突变"'" 4.选择使用 163 信箱的所有记录(按查看次数排序):sql = "select * from data where usermail like ' %"@163.com"%' order by view desc" 5.选择最新的10个记录:sql = "select top 10 * from data order by ID desc" SQL 语句已经知道了,不过在Web应用时,还得创建一个 RecordSet 对象得到记录集,才能把从数据库里取出的值应用在网页上,如果现在将所有的记录显示在网页上就这样: Set conn = Server.CreateObject("ADODB.Connection") conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq="&Server.MapPath("data.mdb") sql = "select * from data" Set rs = Server.CreateObject("ADODB.RecordSet") rs.Open sql,conn,1,1 Do While Not rs.Eof Response.Write " 姓名:"& rs("username") &" E-mail:"& rs("usermail") &" 查看:"& rs("view") &"次 "& rs("indate") &"加入 " rs.MoveNext Loop rs.Close Set rs = Nothing conn.Close Set conn = Nothing 说明:建立数据库连接;创建 rs 得到记录集;循环显示记录,rs.Eof 表示记录末,rs.MoveNext 表示移到下一个记录;最后关闭。 五、修改(更新)数据库记录 修改记录的E-mail: Set conn = Server.CreateObject("ADODB.Connection") conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq="&Server.MapPath("data.mdb") ID = 1 usermail = "fytb@163.com" sql = "update data set usermail='"&usermail&"' where ID="&CInt(ID) conn.Execute(sql) conn.Close Set conn = Nothing 说明:建立数据库连接;获取记录ID、新 E-mail 字符串;使用 update 语句修改记录;conn.Execute 来执行;最后关闭。 如果使记录的查看值加1,则:sql = "update data set view=view+1 where ID="&CInt(ID) 六、删除数据库记录 删除某一条记录: Set conn = Server.CreateObject("ADODB.Connection") conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq="&Server.MapPath("data.mdb") ID = 1 sql = "delete from data where ID="&CInt(ID) conn.Execute(sql) conn.Close Set conn = Nothing 说明:建立数据库连接;获取记录ID;使用 delete 语句删除记录;conn.Execute 来执行;最后关闭。 删除多条记录为:sql = "delete from data where ID in (ID1,ID2,ID3)" 删除所有记录为:sql = "delete from data" 总结: 以上教程是针对ASP的初学者而写的,只是介绍了一些基本的用法,在了解之后可以自己去试试,重要的在于能举一反三、综合运用。更多的语法和参数请参阅 Microsoft Access 帮助中的 Microsoft Jet SQL 参考,由于本人才疏学浅、能力有限,如有表达不明确有地方还望指出,如果在应用当中遇到什么问题,也希望能够提出。谢谢。 在ASP中判断SQL语句是否执行成功 利用err对象: sql="insert into table(f1,f2) values('v1','v2)" conn.execute sql if err.number<>0 then response.write "出错了:"& err.description err.clear else response.write "OK" end if -------------------------------------------------------------------------- 精确到毫秒的时间 下面是一段得到当前时间的JScript函数,精确到毫秒: <script language=jscript runat=server> function GetTime() { var d = new Date(); return d.getTime(); } </script> 在需要测试的程序两端分别用此函数得到两个执行时间值即可测试出代码的执行时间。 倒计时 <html> <head> <title>倒计时-www.51windows.Net</title> <style> .time{color:#ffffff;font-family:verdana,geneva,helveticafont-size:9pt} a:link{text-decoration:none;color:#000000} a:active{text-decoration:none;color:#000000} a:visited{text-decoration:none;color:#000000} a:hover{text-decoration:none;color:#000000} </style> <script language="javascript"> var time_now_server,time_now_client,time_end,time_server_client,timerID; time_end=new Date("Jan 20, 2002 00:00:00"); time_end=time_end.getTime(); time_now_server=new Date("Dec 21, 2001 13:11:1"); time_now_server=time_now_server.getTime(); time_now_client=new Date(); time_now_client=time_now_client.getTime(); time_server_client=time_now_server-time_now_client; setTimeout("show_time()",1000); function show_time() { timer.innerHTML =time_server_client; var time_now,time_distance,str_time; var int_day,int_hour,int_minute,int_second; var time_now=new Date(); time_now=time_now.getTime()+time_server_client; time_distance=time_end-time_now; if(time_distance>0) { int_day=Math.floor(time_distance/86400000) time_distance-=int_day*86400000; int_hour=Math.floor(time_distance/3600000) time_distance-=int_hour*3600000; int_minute=Math.floor(time_distance/60000) time_distance-=int_minute*60000; int_second=Math.floor(time_distance/1000) if(int_hour<10) int_hour="0"+int_hour; if(int_minute<10) int_minute="0"+int_minute; if(int_second<10) int_second="0"+int_second; str_time="<font style='font-size:14pt;color:#28C84A'>"+int_day+"</font><font face='黑体' style='font-size:13pt;'>天</font><br>"+int_hour+":"+int_minute+":"+int_second; timer.innerHTML=str_time; setTimeout("show_time()",1000); } else { timer.innerHTML ="over"; clearTimeout(timerID) } } </script> <style> .time{color:#000000;font-family:verdana;font-size:9pt} </style> </head> <BODY BGCOLOR=#FFFFFF topmargin=2 leftmargin=2> <div id="Layer1" style="position:absolute; width:160px; height:187px; z-index:1"> <!-- begin calendar --> <table width=160 border=0 cellpadding=0 cellspacing=0> <tr> <td colspan=3> </td> </tr> <tr> <td width="47"> </td> <td background="images/mail_03.gif" width="67" valign="top"> <table width=65 cellpadding=3 cellspacing=0 border=0> <tr> <td align=center class="time"> <a href="http://203.212.7.76:8000/Announcement.html"; target=_blank><div id="timer" style="font-size:9pt;color:red"></div></a> </td> </tr> </table> </td> <td width="46"> </td> </tr> <tr> <td colspan=3> </td> </tr> </table> <!-- end calendar --> </div> </BODY> </HTML> <div style="position: absolute; top: 10; right: 10; width: 148; height: 18;cursor:hand"> <input type="button" name="Button" value="查看源代码" onClick= 'window.location = "view-source:" + window.location.href'></div> 当前服务器时间 <script> function tick() { var hours, minutes, seconds, xfile; var intHours, intMinutes, intSeconds; var today; today = new Date(); intHours = today.getHours(); intMinutes = today.getMinutes(); intSeconds = today.getSeconds(); if (intHours == 0) { hours = "12:"; xfile = "午夜"; } else if (intHours < 12) { hours = intHours+":"; xfile = "上午"; } else if (intHours == 12) { hours = "12:"; xfile = "正午"; } else { intHours = intHours - 12 hours = intHours + ":"; xfile = "下午"; } if (intMinutes < 10) { minutes = "0"+intMinutes+":"; } else { minutes = intMinutes+":"; } if (intSeconds < 10) { seconds = "0"+intSeconds+" "; } else { seconds = intSeconds+" "; } timeString = xfile+hours+minutes+seconds; Clock.innerHTML = timeString; window.setTimeout("tick();", 100); } window.onload = tick; </script> <font id="Clock" align="center" style="font-size: 20; color:#000000"></font> ----------------------------------------------------------------- 日历 <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>html-www.51windows.Net</title> </head> <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript"> //创建一个数组,用于存放每个月的天数 function montharr(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11) { this[0] = m0; this[1] = m1; this[2] = m2; this[3] = m3; this[4] = m4; this[5] = m5; this[6] = m6; this[7] = m7; this[8] = m8; this[9] = m9; this[10] = m10; this[11] = m11; } //实现月历 function calendar() { var monthNames = "JanFebMarAprMayJunJulAugSepOctNovDec"; var today = new Date(); var thisDay; var monthDays = new montharr(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); year = today.getYear() +1900; thisDay = today.getDate(); if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) monthDays[1] = 29; nDays = monthDays[today.getMonth()]; firstDay = today; firstDay.setDate(1); testMe = firstDay.getDate(); if (testMe == 2) firstDay.setDate(0); startDay = firstDay.getDay(); document.write("<TABLE BORDER='0' CELLSPACING='0' CELLPADDING='2' ALIGN='CENTER' BGCOLOR='#0080FF'>") document.write("<TR><TD><table border='0' cellspacing='1' cellpadding='2' bgcolor='Silver'>"); document.write("<TR><th colspan='7' bgcolor='#C8E3FF'>"); var dayNames = new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六"); var monthNames = new Array("1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"); var now = new Date(); document.writeln("<FONT STYLE='font-size:9pt;Color:#330099'>" + "公元 " + now.getYear() + "年" + monthNames[now.getMonth()] + " " + now.getDate() + "日 " + dayNames[now.getDay()] + "</FONT>"); document.writeln("</TH></TR><TR><TH BGCOLOR='#0080FF'><FONT STYLE='font-size:9pt;Color:White'>日</FONT></TH>"); document.writeln("<th bgcolor='#0080FF'><FONT STYLE='font-size:9pt;Color:White'>一</FONT></TH>"); document.writeln("<TH BGCOLOR='#0080FF'><FONT STYLE='font-size:9pt;Color:White'>二</FONT></TH>"); document.writeln("<TH BGCOLOR='#0080FF'><FONT STYLE='font-size:9pt;Color:White'>三</FONT></TH>"); document.writeln("<TH BGCOLOR='#0080FF'><FONT STYLE='font-size:9pt;Color:White'>四</FONT></TH>"); document.writeln("<TH BGCOLOR='#0080FF'><FONT STYLE='font-size:9pt;Color:White'>五</FONT></TH>"); document.writeln("<TH BGCOLOR='#0080FF'><FONT STYLE='font-size:9pt;Color:White'>六</FONT></TH>"); document.writeln("</TR><TR>"); column = 0; for (i=0; i<startDay; i++) { document.writeln("\n<TD><FONT STYLE='font-size:9pt'> </FONT></TD>"); column++; } for (i=1; i<=nDays; i++) { if (i == thisDay) { document.writeln("</TD><TD ALIGN='CENTER' BGCOLOR='#FF8040'><FONT STYLE='font-size:9pt;Color:#ffffff'><B>") } else { document.writeln("</TD><TD BGCOLOR='#FFFFFF' ALIGN='CENTER'><FONT STYLE='font-size:9pt;font-family:Arial;font-weight:bold;Color:#330066'>"); } document.writeln(i); if (i == thisDay) document.writeln("</FONT></TD>") column++; if (column == 7) { document.writeln("<TR>"); column = 0; } } document.writeln("<TR><TD COLSPAN='7' ALIGN='CENTER' VALIGN='TOP' BGCOLOR='#0080FF'>") document.writeln("<FORM NAME='clock' onSubmit='0'><FONT STYLE='font-size:9pt;Color:#ffffff'>") document.writeln("现在时间:<INPUT TYPE='Text' NAME='face' ALIGN='TOP'></FONT></TD></TR></TABLE>") document.writeln("</TD></TR></TABLE></FORM>"); } </SCRIPT> <SCRIPT LANGUAGE="JavaScript"> var timerID = null; var timerRunning = false; function stopclock (){ if(timerRunning) clearTimeout(timerID); timerRunning = false;} //显示当前时间 function showtime () { var now = new Date(); var hours = now.getHours(); var minutes = now.getMinutes(); var seconds = now.getSeconds() var timeValue = " " + ((hours >12) ? hours -12 :hours) timeValue += ((minutes < 10) ? ":0" : ":") + minutes timeValue += ((seconds < 10) ? ":0" : ":") + seconds timeValue += (hours >= 12) ? " 下午 " : " 上午 " document.clock.face.value = timeValue; timerID = setTimeout("showtime()",1000);//设置超时,使时间动态显示 timerRunning = true;} function startclock () { stopclock(); showtime();} </SCRIPT> <BODY onLoad="startclock(); timerONE=window.setTimeout" TEXT="#000000"> <B><DIV ALIGN="center"></DIV> <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript"> <!-- document.write("") calendar(); //--> </SCRIPT> </body> </html> <div style="position: absolute; top: 10; right: 10; width: 148; height: 18;cursor:hand"> <input type="button" name="Button" value="查看源代码" onClick= 'window.location = "view-source:" + window.location.href'></div> ---------------------------------------------------------------------- |
|
||
| re:日历和时间钟 日历和时间钟 <HTML> <HEAD> <TITLE>日历和时间钟-www.51windows.Net</TITLE> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> </HEAD> <BODY> <style type="text/css"> body { background-color: #D4D0C8; } .m_fieldset { padding: 0,10,5,10; text-align: center; width: 150px; } .m_legend { font-family: Tahoma; font-size: 11px; padding-bottom: 5px; } .m_frameborder { border-left: 2px inset #D4D0C8; border-top: 2px inset #D4D0C8; border-right: 2px inset #FFFFFF; border-bottom: 2px inset #FFFFFF; width: 100px; height: 19px; background-color: #FFFFFF; overflow: hidden; text-align: right; font-family: "Tahoma"; font-size: 10px; } .m_arrow { width: 16px; height: 8px; font-family: "Webdings"; font-size: 7px; line-height: 2px; padding-left: 2px; cursor: default; } .m_input { width: 18px; height: 14px; border: 0px solid black; font-family: "Tahoma"; font-size: 9px; text-align: right; ime-mode:disabled; } .c_fieldset { padding: 0,10,5,10; text-align: center; width: 180px; } .c_legend { font-family: Tahoma; font-size: 11px; padding-bottom: 5px; } .c_frameborder { border-left: 2px inset #D4D0C8; border-top: 2px inset #D4D0C8; border-right: 2px inset #FFFFFF; border-bottom: 2px inset #FFFFFF; background-color: #FFFFFF; overflow: hidden; font-family: "Tahoma"; font-size: 10px; width:160px; height:120px; } .c_frameborder td { width: 23px; height: 16px; font-family: "Tahoma"; font-size: 11px; text-align: center; cursor: default; } .c_frameborder .selected { background-color:#0A246A; width:12px; height:12px; color:white; } .c_frameborder span { width:12px; height:12px; } .c_arrow { width: 16px; height: 8px; font-family: "Webdings"; font-size: 7px; line-height: 2px; padding-left: 2px; cursor: default; } .c_year { font-family: "Tahoma"; font-size: 11px; cursor: default; width:55px; height:19px; } .c_month { width:75px; height:20px; font:11px "Tahoma"; } .c_dateHead { background-color:#808080; color:#D4D0C8; } </style> <script language="javascript"> // Written by cloudchen, 2004/03/15 function minute(name,fName) { this.name = name; this.fName = fName || "m_input"; this.timer = null; this.fObj = null; this.toString = function() { var objDate = new Date(); var sMinute_Common = "class=\"m_input\" maxlength=\"2\" name=\""+this.fName+"\" onfocus=\""+this.name+".setFocusObj(this)\" onblur=\""+this.name+".setTime(this)\" onkeyup=\""+this.name+".prevent(this)\" onkeypress=\"if (!/[0-9]/.test(String.fromCharCode(event.keyCode)))event.keyCode=0\" onpaste=\"return false\" ondragenter=\"return false\""; var sButton_Common = "class=\"m_arrow\" onfocus=\"this.blur()\" onmouseup=\""+this.name+".controlTime()\" disabled" var str = ""; str += "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">" str += "<tr>" str += "<td>" str += "<div class=\"m_frameborder\">" str += "<input radix=\"24\" value=\""+this.formatTime(objDate.getHours())+"\" "+sMinute_Common+">:" str += "<input radix=\"60\" value=\""+this.formatTime(objDate.getMinutes())+"\" "+sMinute_Common+">:" str += "<input radix=\"60\" value=\""+this.formatTime(objDate.getSeconds())+"\" "+sMinute_Common+">" str += "</div>" str += "</td>" str += "<td>" str += "<table border=\"0\" cellspacing=\"2\" cellpadding=\"0\">" str += "<tr><td><button id=\""+this.fName+"_up\" "+sButton_Common+">5</button></td></tr>" str += "<tr><td><button id=\""+this.fName+"_down\" "+sButton_Common+">6</button></td></tr>" str += "</table>" str += "</td>" str += "</tr>" str += "</table>" return str; } this.play = function() { this.timer = setInterval(this.name+".playback()",1000); } this.formatTime = function(sTime) { sTime = ("0"+sTime); return sTime.substr(sTime.length-2); } this.playback = function() { var objDate = new Date(); var arrDate = [objDate.getHours(),objDate.getMinutes(),objDate.getSeconds()]; var objMinute = document.getElementsByName(this.fName); for (var i=0;i<objMinute.length;i++) { objMinute.value = this.formatTime(arrDate) } } this.prevent = function(obj) { clearInterval(this.timer); this.setFocusObj(obj); var value = parseInt(obj.value,10); var radix = parseInt(obj.radix,10)-1; if (obj.value>radix||obj.value<0) { obj.value = obj.value.substr(0,1); } } this.controlTime = function(cmd) { event.cancelBubble = true; if (!this.fObj) return; clearInterval(this.timer); var cmd = event.srcElement.innerText=="5"?true:false; var i = parseInt(this.fObj.value,10); var radix = parseInt(this.fObj.radix,10)-1; if (i==radix&&cmd) { i = 0; } else if (i==0&&!cmd) { i = radix; } else { cmd?i++:i--; } this.fObj.value = this.formatTime(i); this.fObj.select(); } this.setTime = function(obj) { obj.value = this.formatTime(obj.value); } this.setFocusObj = function(obj) { eval(this.fName+"_up").disabled = eval(this.fName+"_down").disabled = false; this.fObj = obj; } this.getTime = function() { var arrTime = new Array(2); for (var i=0;i<document.getElementsByName(this.fName).length;i++) { arrTime = document.getElementsByName(this.fName).value; } return arrTime.join(":"); } } </script> <script language="javascript"> // Written by cloudchen, 2004/03/16 function calendar(name,fName) { this.name = name; this.fName = fName || "calendar"; this.year = new Date().getFullYear(); this.month = new Date().getMonth(); this.date = new Date().getDate(); //private this.toString = function() { var str = ""; str += "<table border=\"0\" cellspacing=\"3\" cellpadding=\"0\" onselectstart=\"return false\">"; str += "<tr>"; str += "<td>"; str += this.drawMonth(); str += "</td>"; str += "<td align=\"right\">"; str += this.drawYear(); str += "</td>"; str += "</tr>"; str += "<tr>"; str += "<td colspan=\"2\">"; str += "<div class=\"c_frameborder\">"; str += "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"c_dateHead\">"; str += "<tr>"; str += "<td>日</td><td>一</td><td>二</td><td>三</td><td>四</td><td>五</td><td>六</td>"; str += "</tr>"; str += "</table>"; str += this.drawDate(); str += "</div>"; str += "</td>"; str += "</tr>"; str += "</table>"; return str; } //private this.drawYear = function() { var str = ""; str += "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"; str += "<tr>"; str += "<td>"; str += "<input class=\"c_year\" maxlength=\"4\" value=\""+this.year+"\" name=\""+this.fName+"\" id=\""+this.fName+"_year\" readonly>"; //DateField str += "<input type=\"hidden\" name=\""+this.fName+"\" value=\""+this.date+"\" id=\""+this.fName+"_date\">"; str += "</td>"; str += "<td>"; str += "<table cellspacing=\"2\" cellpadding=\"0\" border=\"0\">"; str += "<tr>"; str += "<td><button class=\"c_arrow\" onfocus=\"this.blur()\" onclick=\"event.cancelBubble=true;document.getElementById('"+this.fName+"_year').value++;"+this.name+".redrawDate()\">5</button></td>"; str += "</tr>"; str += "<tr>"; str += "<td><button class=\"c_arrow\" onfocus=\"this.blur()\" onclick=\"event.cancelBubble=true;document.getElementById('"+this.fName+"_year').value--;"+this.name+".redrawDate()\">6</button></td>"; str += "</tr>"; str += "</table>"; str += "</td>"; str += "</tr>"; str += "</table>"; return str; } //priavate this.drawMonth = function() { var aMonthName = ["一","二","三","四","五","六","七","八","九","十","十一","十二"]; var str = ""; str += "<select class=\"c_month\" name=\""+this.fName+"\" id=\""+this.fName+"_month\" onchange=\""+this.name+".redrawDate()\">"; for (var i=0;i<aMonthName.length;i++) { str += "<option value=\""+(i+1)+"\" "+(i==this.month?"selected":"")+">"+aMonthName+"月</option>"; } str += "</select>"; return str; } //private this.drawDate = function() { var str = ""; var fDay = new Date(this.year,this.month,1).getDay(); var fDate = 1-fDay; var lDay = new Date(this.year,this.month+1,0).getDay(); var lDate = new Date(this.year,this.month+1,0).getDate(); str += "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" id=\""+this.fName+"_dateTable"+"\">"; for (var i=1,j=fDate;i<7;i++) { str += "<tr>"; for (var k=0;k<7;k++) { str += "<td><span"+(j==this.date?" class=\"selected\"":"")+" onclick=\""+this.name+".redrawDate(this.innerText)\">"+(isDate(j++))+"</span></td>"; } str += "</tr>"; } str += "</table>"; return str; function isDate(n) { return (n>=1&&n<=lDate)?n:""; } } //public this.redrawDate = function(d) { this.year = document.getElementById(this.fName+"_year").value; this.month = document.getElementById(this.fName+"_month").value-1; this.date = d || this.date; document.getElementById(this.fName+"_year").value = this.year; document.getElementById(this.fName+"_month").selectedIndex = this.month; document.getElementById(this.fName+"_date").value = this.date; if (this.date>new Date(this.year,this.month+1,0).getDate()) this.date = new Date(this.year,this.month+1,0).getDate(); document.getElementById(this.fName+"_dateTable").outerHTML = this.drawDate(); } //public this.getDate = function(delimiter) { if (!delimiter) delimiter = "/"; var aValue = [this.year,(this.month+1),this.date]; return aValue.join(delimiter); } } </script> <table border="0"> <tr><td> <fieldset class="c_fieldset"><legend class="c_legend">日期(T)</legend> <!-- 调用日历 --> <script> var c = new calendar("c"); document.write(c); </script> <!-- 调用日历 --> </fieldset> </td> <td valign="top"> <fieldset class="m_fieldset"><legend class="m_legend">时间(T)</legend> <!-- 调用时间钟 --> <script> var m = new minute("m"); m.play(); document.write(m); </script> <!-- 调用时间钟 --> </fieldset> </td></tr> <tr> <td colspan="2"> <button onclick="alert(c.getDate())" style="font:8px Webdings;width:15px;height:15px;line-height:6px;">4</button> <button style="font:10px Arial;height:15px;height:16px;border:0px;" onfocus="this.blur()">GetDate</button> <button onclick="alert(m.getTime())" style="font:8px Webdings;width:15px;height:15px;line-height:6px;">4</button> <button style="font:10px Arial;height:15px;height:16px;border:0px;" onfocus="this.blur()">GetTime</button> </td> </tr> </table> </BODY> </HTML> <div style="position: absolute; top: 10; right: 10; width: 148; height: 18;cursor:hand"> <input type="button" name="Button" value="查看源代码" onClick= 'window.location = "view-source:" + window.location.href'></div> ------------------------------------------------------------ 有下拉菜单的复选 <HTML> <HEAD> <TITLE>有下拉菜单的复选-www.51windows.Net</TITLE> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <META NAME="Author" CONTENT="51windows,海娃,haiwa"> <META NAME="Description" CONTENT="Power by 51windows.Net"> </HEAD> <body bgcolor="#336699"> <div id=haiwa style="background-color: #EEEEEE; border: 1 solid #000000; width: 120; height: 20;overflow:auto" onmouseover=this.style.height="120"; onmouseout=haiwa.style.height='20';> <SCRIPT language=JavaScript> var i=0; for(i=1;i<20;i++) { document.write("<div style=\"height:20px;cursor:default;font-family: Tahoma; font-size: 12px; font-weight: bold\" onclick=haiwa.style.height=\"20\";document.all.haiwa.scrollTop=0><input type='checkbox' style='height:15px;' name='ck' id=ck"+i+"><label for='ck"+i+"'>第"+i+"项</label></div>"); } </SCRIPT> </div> </body> </html> <div style="position: absolute; top: 10; right: 10; width: 148; height: 18;cursor:hand"> <input type="button" name="Button" value="查看源代码" onClick= 'window.location = "view-source:" + window.location.href'></div> ------------------------------------------------------------------ <html> <head> <title>List</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <script LANGUAGE="javascript"> <!-- var onecount; onecount=0; subcat = new Array(); subcat[0] = new Array("徐汇区","01","001"); subcat[1] = new Array("嘉定区","01","002"); subcat[2] = new Array("黄浦区","01","003"); subcat[3] = new Array("南昌市","02","004"); subcat[4] = new Array("九江市","02","005"); subcat[5] = new Array("上饶市","02","006"); onecount=6; function changelocation(locationid) { document.myform.smalllocation.length = 0; var locationid=locationid; var i; document.myform.smalllocation.options[0] = new Option('====所有地区====',''); for (i=0;i < onecount; i++) { if (subcat[1] == locationid) { document.myform.smalllocation.options[document.myform.smalllocation.length] = new Option(subcat[0], subcat[2]); } } } //--> </script> </head> <body> <form name="myform" method="post"> <select name="biglocation" onChange="changelocation(document.myform.biglocation.options[document.myform.biglocation.selectedIndex].value)"> <option value="01" selected>上海</option> <option value="02">江西</option> </select> <select name="smalllocation"> <option selected value="">==所有地区==</option> </select> </form> <script LANGUAGE="javascript"> <!-- changelocation(document.myform.biglocation.options[document.myform.biglocation.selectedIndex].value); //--> </script> </body> </html> 下拉框连动的小例子(数据库版) 【钢铁工人】 于 2000-11-2 10:35:06 加贴在 Joy ASP ↑: ASP文件: <%@ Language=VBScript %> <%Option Explicit%> <html> <head> <title>List</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <% dim conn dim rs dim sql dim count dim rs1 dim sql1 set conn = server.CreateObject ("adodb.connection") conn.Open "test","sa","" sql = "select * from district order by locationid asc" set rs = conn.execute(sql) %> <script language = "JavaScript"> var onecount; onecount=0; subcat = new Array(); <% count = 0 do while not rs.eof %> subcat[<%=count%>] = new Array("<%= trim(rs("districtname"))%>","<%= trim(rs("locationid"))%>","<%= trim(rs("districtid"))%>"); <% count = count + 1 rs.movenext loop rs.close set rs=nothing %> onecount=<%=count%>; function changelocation(locationid) { document.myform.smalllocation.length = 0; var locationid=locationid; var i; document.myform.smalllocation.options[0] = new Option('====所有地区====',''); for (i=0;i < onecount; i++) { if (subcat[1] == locationid) { document.myform.smalllocation.options[document.myform.smalllocation.length] = new Option(subcat[0], subcat[2]); } } } </script> </head> <body> <form name="myform" method="post"> <select name="biglocation" onChange="changelocation(document.myform.biglocation.options[document.myform.biglocation.selectedIndex].value)"> <% sql1 = "select * from location order by locationname asc" set rs1 = conn.Execute (sql1) do while not rs1.eof %> <option value="<%=trim(rs1("locationid"))%>"><%=trim(rs1("locationname"))%></option> <% rs1.movenext loop rs1.close set rs1 = nothing conn.Close set conn = nothing %> </select> <select name="smalllocation"> <option selected value="">==所有地区==</option> </select> </form> <script LANGUAGE="javascript"> changelocation(document.myform.biglocation.options[document.myform.biglocation.selectedIndex].value); </script> </body> </html> 数据库: create table location ( locationid char(2) not null primary key, locationname char(50) not null ) create table district ( districtid char(3) not null primary key, districtname char(50) not null, locationid char(2) not null ) |
浙公网安备 33010602011771号