分享
 
 
 

常用ASP代码(一)

王朝asp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

获取页面的HTML

<script>

var oXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");

oXmlHttp.open("GET","http://www.163.com", false);

oXmlHttp.send()

var oStream = new ActiveXObject("ADODB.Stream");

if(oStream == null)

alert("您的机器不支持ADODB.Stream.")

else

{

oStream.Type=1;

oStream.Mode=3;

oStream.Open() ;

oStream.Write(oXmlHttp.responseBody);

oStream.Position= 0;

oStream.Type= 2;

oStream.Charset="gb2312";

var result= oStream.ReadText();

oStream.Close();

oStream = null;

var aa = window.open("","")

document.write(result);

aa.document.write(result);

}

</script>

[新开一个窗口]============================================================================================================

window.open('filename','','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=400,height=570,top=200,left=300,bottom=0,right=0');

[关于JS调用]============================================================================================================

new.asp(调用文件)

<%

str = "循环取的要调用的数据"

'关键是下面这句,调用document函数打印输入str值--->

%>

document.write('<%=str%>')

OK,结束,在其他要调用的页面插入

<script language="javascript" src="new文件所在目录/news.asp></script>

[打开一个窗口,并且关闭当前窗口]============================================================================================================

<script language="JavaScript">

//-->

window.open('MenuMain.asp','','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=,height=,top=0,left=0,bottom=0,right=0');

window.opener = "meizz"; //加了这句代码IE5.5+不会有关闭提示

window.close();

//--

</script>

[分页显示记录]============================================================================================================

一.

<%

dim MaxPerPage

dim totalPage

if not isempty(request("page")) then

currentPage=cint(request("page"))

else

currentPage=1

end if

%>

二.

<%

set rs=server.createobject("adodb.recordset")

sql="select top 20 * from person order by id desc"

rs.open sql,conn,1,1

if rs.eof and rs.bof then

response.write "没有任何人才信息"

else

rs.pagesize=10

MaxPerPage=rs.pagesize

totalPage=rs.pagecount

if CurrentPage<1 then

CurrentPage=1

end if

if CurrentPage>totalPage then

CurrentPage=totalPage

end if

if CurrentPage>1 then

rs.move (CurrentPage-1)*MaxPerPage

dim bookmark

bookmark rs.bookmark

end if

i=1

do while not rs.eof and i<=10

%>

......本页显示的数据

<%

i=i+1

rs.movenext

loop

end if

rs.close

%>

三.

<a href="allrencai.asp?page=1>第一页&nbsp;&nbsp</a>

<a href="allrencai.asp?page=<%=CurrentPage-1%>上一页&nbsp;&nbsp;</a>

<a href="allrencai.asp?page=<%=CurrentPage+1%>">下一页&nbsp;&nbsp;</a>

<a href="allrencai.asp?page=<%=totalPage%>最末页</a>

按照上面的模式套进去就可以了,应该没什么问题!

[获取用户IP]============================================================================================================

request.servervariables("remote_addr")

[对象的显示与隐藏(style.display的应用)]============================================================================================================

document.name.style.display="none"; //隐藏

document.name.style.display="block"; //显示

[改变文本字体大小]============================================================================================================

<SCRIPT LANGUAGE="JavaScript">

<!--

function fontZoom(size)

{

document.getElementById("fontzoom").style.fontSize=size+"px"

}

//-->

</SCRIPT>

<TABLE>

<TR>

<TD id="fontzoom">1234fsdfsdfasd234234311dfasdfsd23</TD>

<TD><a href="javascript:fontZoom(12)">12</a></TD>

<TD><a href="javascript:fontZoom(18)">18</a></TD>

</TR>

</TABLE>

[随机抽取记录]============================================================================================================

rs.moveFirst

randomize

rs.move int(rnd*rs.recordCount)

[获取ID为R1的RADIO的值]============================================================================================================

<FORM name="form1" METHOD=POST ACTION="">

<INPUT type=radio value=l name="r1">左对齐

<INPUT type=radio value=r name="r1">右对齐

<INPUT type=radio CHECKED value=m name="r1">中间对齐

<INPUT type=radio value=s name="r1">两端对齐

<INPUT TYPE="button" name="cmd" value="getValue" onclick="getValue()">

</FORM>

<script language="javascript">

<!--

function getValue()

{

var msg="";

var i=0;

for(i=0;i<document.all.form1.r1.length;i++)

if(document.all.form1.r1[i].checked)alert(document.all.form1.r1[i].value);

}

-->

</script>

[向一个frame中载入页面]============================================================================================================

<HTML>

<HEAD>

<script language="JavaScript">

<!-- Hiding

function loadtwo(page2, page3) {

parent.fr2.location.href=page2;

parent.fr3.location.href=page3;

}

// -->

</script>

</HEAD>

<BODY>

<FORM NAME="buttons">

<INPUT TYPE="button" VALUE="同 时 载 入 两 份 文 件" onClick="loadtwo('frtest1.html',

'frtest2.html')">

</FORM>

</BODY>

</HTML>

[ASP动态输出一个图片或FLASH]============================================================================================================

<%

if rsDB("fileType")<>"SWF" then

%>

<a href="<%=rsDB("linkURL")%>" name="logoIMGLINK" target="_blank"><img src="/admin/adver/upload/<%=rsDB("id")%>.<%=rsDB("filetype")%>" width="550" height="100" name="logoIMG" border="0"></a>

<%

else

response.Write("<object classid=""clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"" codebase=""http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0"" width=""550"" height=""100""> <param name=""movie"" value=""/admin/adver/upload/"+cstr(rsDB("id"))+"."+rsDB("filetype")+"""> <param name=""quality"" value=""high""> <embed src=""/admin/adver/upload/"+cstr(rsDB("id"))+"."+rsDB("filetype")+" quality=""high"" pluginspage=""http://www.macromedia.com/go/getflashplayer"" type=""application/x-shockwave-flash"" width=""550"" height=""100""></embed></object>")

end if

%>

[连接SQL数据库]============================================================================================================

set dcnDB = server.createobject("ADODB.CONNECTION")

dcnDB.open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=帐号;pwd=密码;Initial Catalog=表名;Data Source=数据库IP(localhost本地)"

set rsDB = server.createobject("ADODB.RECORDSET")

[模糊查找(SQL数据库)]============================================================================================================

sql="SELECT * FROM [USER] WHERE User_Name like '%XXXXX%'"

[SQL数据库中时间的表示方法]============================================================================================================

sql="SELECT * FROM [USER] WHERE [date]<'2004-4-7'"

[浮动广告]============================================================================================================

第一步:把如下代码加入<head>区域中

<script language="JavaScript">

<!--//

//设置下面一些参数,小球移动速度1-50,数值大速度快;

var ballWidth = 40;

var ballHeight = 40;

var BallSpeed = 10;

var maxBallSpeed = 50;

var xMax;

var yMax;

var xPos = 0;

var yPos = 0;

var xDir = 'right'; //水平方向向右移动

var yDir = 'down'; //垂直方向向下移动

var superballRunning = true;

var tempBallSpeed;

var currentBallSrc;

var newXDir;

var newYDir;

function initializeBall() {

if (document.all) {

xMax = document.body.clientWidth

yMax = document.body.clientHeight

document.all("superball").style.visibility = "visible";

}

else if (document.layers) {

xMax = window.innerWidth;

yMax = window.innerHeight;

document.layers["superball"].visibility = "show";

}

setTimeout('moveBall()',400);

}

function moveBall() {

if (superballRunning == true) {

calculatePosition();

if (document.all) {

document.all("superball").style.left = xPos + document.body.scrollLeft;

document.all("superball").style.top = yPos + document.body.scrollTop;

}

else if (document.layers) {

document.layers["superball"].left = xPos + pageXOffset;

document.layers["superball"].top = yPos + pageYOffset;

}

setTimeout('moveBall()',30);

}

}

function calculatePosition() {

if (xDir == "right") {

if (xPos > (xMax - ballWidth - BallSpeed)) {

xDir = "left";

}

}

else if (xDir == "left") {

if (xPos < (0 + BallSpeed)) {

xDir = "right";

}

}

if (yDir == "down") {

if (yPos > (yMax - ballHeight - BallSpeed)) {

yDir = "up";

}

}

else if (yDir == "up") {

if (yPos < (0 + BallSpeed)) {

yDir = "down";

}

}

if (xDir == "right") {

xPos = xPos + BallSpeed;

}

else if (xDir == "left") {

xPos = xPos - BallSpeed;

}

else {

xPos = xPos;

}

if (yDir == "down") {

yPos = yPos + BallSpeed;

}

else if (yDir == "up") {

yPos = yPos - BallSpeed;

}

else {

yPos = yPos;

}

}

if (document.all||document.layers)

window.onload = initializeBall;

window.onresize = new Function("window.location.reload()");

// -->

</script>

<style type="text/css">

#superball {

position:absolute;

left:0;

top:0;

visibility:hide;

visibility:hidden;

width:40;

height:40;

}

</style>

第二步:把如下代码加入区域中:

16:16 2004-4-11

[判断文件是否存在]=============================================================================================

Set fs = server.CreateObject("scripting.filesystemobject")

if fs.FileExists(filename) then

fs.DeleteFile(filename)

end if

[用WebEasyMail发送邮件]==================================================================================

'以下是一段找回密码的过程!

sub Send_EM()

Dim mailsend

Dim sender

str="尊敬的"&request("PSQname")&":"

str=str&"<p>"

str=str&"<br/>"

str=str&"&nbsp;&nbsp;&nbsp;&nbsp;您登录密码为:"&rsDB("Password")&",请务必记住此登陆码,<br/>因为您必须以此登陆码才能登陆本站。"

str=str&"<br/>"

str=str&"&nbsp;&nbsp;&nbsp;&nbsp;如果您注册的是高级会员,请等待验证和通知。"

str=str&"<br/>"

str=str&"&nbsp;&nbsp;&nbsp;&nbsp;希望能给您带来新的收获,顺祝收成日丰!"

str=str&"<br/>"

str=str&"<hr>"

str=str&"<br/>"

str=str&"&nbsp;&nbsp;&nbsp;&nbsp;Road Lab Xi'an China"

str=str& "&nbsp;&nbsp;&nbsp;&nbsp;E-mail:webmaster@roadhome.net"

Set mailsend = Server.CreateObject("easymail.MailSend")

mailsend.CreateNew "webmaster@roadhome.net","登录密码"

' 发信人名称

mailsend.MailName = "Road Lab Xi'an China"

mailsend.EM_To =rsDB("email")

'收件人邮件地址

mailsend.EM_Subject = "找回密码!!" '邮件主题"

mailsend.EM_HTML_Text =str

mailsend.useRichEditer = true

mailsend.send

set mailsend=nothing

end sub

[过滤html标签获得纯字符]====================================================================================

<SCRIPT LANGUAGE="vbScript">

Function RegExpTest(patrn, strng)

Dim regEx, Match, Matches '建立变量。

Set regEx = New RegExp '建立正则表达式。

regEx.Pattern = patrn'设置模式。

regEx.IgnoreCase = True '设置是否区分字符大小写。

regEx.Global = True '设置全局可用性。

Set Matches = regEx.Execute(strng)'执行搜索。

dim rtStr

rtStr=strng

For Each Match in Matches'遍历匹配集合。

rtStr=replace(rtStr,Match.value,"")

Next

RegExpTest = rtStr

End Function

Content=RegExpTest("<.*?>", Content)

</SCRIPT>

[解决XMLHTTP POST数据乱码问题]===============================================================================

function getValue()

dim xmlDom

set xmlDom=createobject("MSXML2.XMLHTTP")

xmlDom.open "POST","http://dheart.51.net/ip/index.php?ip=10.100.1.11",false

xmlDom.send

msgbox(bytes2BSTR(xmlDom.responsebody))

end function

Function bytes2BSTR(vIn)

strReturn = ""

For i = 1 To LenB(vIn)

ThisCharCode = AscB(MidB(vIn,i,1))

If ThisCharCode < &H80 Then

strReturn = strReturn & Chr(ThisCharCode)

Else

NextCharCode = AscB(MidB(vIn,i+1,1))

strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))

i = i + 1

End If

Next

bytes2BSTR = strReturn

End Function

[SQL修改库结构]

strsql="ALTER TABLE product ADD orderID int NULL"

conn.execute(strsql)

[把DOC转成HTML文件]=============================================================================================

<HTML>

<HEAD>

<TITLE>WalkingPoison's Word-to-HTML sample</TITLE>

<script language=javascript>

function saveword(){

var oWordApp=new ActiveXObject("Word.Application");

var oDocument=oWordApp.Documents.Open("C:\\temp.doc");

oDocument.SaveAs("C:\\test.htm",8)

oWordApp.Quit();

getDOC.innerHTML=""

}

function getIframeDoc(){

alert(iframeDOC.value);

}

</script>

</HEAD>

<BODY>

Click the "save" button to save the file "C:\test.doc" to "C:\test.htm":

<input type=button onclick="saveword()" value=save>

<button onclick="getIframeDoc()">GetDoc.HTML</button>

<P>&nbsp;</P> <iframe src='c:\test.htm' id='iframeDOC'></iframe>

<div id="getDOC"></div>

</BODY>

</HTML>

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有