本文目录一览:
js函数转换ASP版
script language="jscript" runat="server"
// 加上 runat="server", script block 就是服务端运行, jscript 定义的函数就可以被 VBScript 直接调用
function sayHello(p) {
Response.Write("Hello! " + p + ".");
}
/script
% Call sayHello("Jack") %
js 代码转化成ASP代码
javascript运行在客户端,而asp运行在服务器端
要想asp接受到javascript中的变量,就的把javascript中的变量提交到asp中
方法比较多,下面是一个比较简单的方法
修改你原来的javascript
a href="javascript:extractlinks()"点击测试下含有的链接?/a
script language="JavaScript1.2" defer="defer"
!--
function extractlinks(){
var links=document.all.tags("A")
var strlinks='';
b=0
var total=links.length
var win2=window.open("","","menubar,scrollbars,toolbar")
for (i=0;itotal;i++)
{
if ((links[i].href).indexOf("www")!=-1
(links[i].href.length )35) {
//win2.document.write("font size='2'"+links[i]+"/fontbr");
strlinks += links[i]+'|';
b++;
}
}
//win2.document.write("font size='2'一共有"+b+"个外部连接/fontbr")
win2.location.href='view.asp?link='+strlinks;
}
--
/script
新建一个view.asp
%
link = Request.QueryString("link")
links =split(link,"|",-1,1)
for each str in links
Response.Write(str+"br")
next
%
你就可以把就要把javascript中的变量提交到asp中
你还用现在流行的ajax把javascript中的变量提交到asp中
js脚本变量如何变成asp变量
script
function bbb(){
if(document.souform.keyword.value==""||document.souform.keyword.value=='请输入关键字!'){
alert("请输入关键字!");
return false ;
}
return true
}
function eee(){
if(document.souform.keyword.value=='请输入关键字!'){
document.souform.keyword.value="";
}
}
/script
%
set rs=server.createobject("adodb.recordset")
sql = "select * from smallclass order by smallclassID asc"
rs.open sql,conn,1,1
%
script language = "JavaScript"
var onecount;
subcat = new Array();
%
count = 0
do while not rs.eof
%
subcat[%=count%] = new Array("%= trim(rs("smallclassName"))%","%= trim(rs("bigclassName"))%","%= trim(rs("smallclassName"))%");
%
count = count + 1
rs.movenext
loop
rs.close
%
onecount=%=count%;
function aaa(locationid)
{
document.souform.smallclassName.length = 1;
var locationid=locationid;
var i;
for (i=0;i onecount; i++)
{
if (subcat[i][1] == locationid)
{
document.souform.smallclassName.options[document.souform.smallclassName.length] = new Option(subcat[i][0], subcat[i][2]);
}
}
}
/script
form name="souform" method="post" action="searchslt_in_site.asp" onSubmit="return bbb();"
%
sql = "select * from bigclass"
rs.open sql,conn,1,1
if rs.eof and rs.bof then
response.write "请先添加栏目。"
else
%
select name="bigclassName" onChange="aaa(document.souform.bigclassName.options[document.souform.bigclassName.selectedIndex].value)" size="1"
option selected value="%=trim(rs("bigclassName"))%"%=trim(rs("bigclassName"))%/option
%
dim selclass
selclass=rs("bigclassName")
rs.movenext
do while not rs.eof
%
option value="%=trim(rs("bigclassName"))%"%=trim(rs("bigclassName"))%/option
%
rs.movenext
loop
end if
rs.close
%
/select select name="smallclassName"
option value="" selected/option
%
sql="select * from smallclass where bigclassName='" selclass "'"
rs.open sql,conn,1,1
if not(rs.eof and rs.bof) then
%
option value="%=rs("smallclassName")%"%=rs("smallclassName")%/option
% rs.movenext
do while not rs.eof%
option value="%=rs("smallclassName")%"%=rs("smallclassName")%/option
%
rs.movenext
loop
end if
rs.close
%
%
ranNum=int(9*rnd)+10
iddata=month(now)day(now)hour(now)minute(now)second(now)ranNum
%
/select
关键字:
input type="text" name="keyword" size="20" onmousedown="eee()" value="请输入关键字!"
input type="radio" name="selection" value="title" checked按标题搜
input type="radio" name="selection" value="content"按内容搜
input type="submit" name="Submit" value="提交" class="input"
input type="reset" name="Submit2" value="重置" class="input"
/form
这是我做一个搜索的时间做的一个下拉菜单自动生成的程序,自己好好研究下吧
js 代码 改写 为 asp代码
不用写,直接用js标签的runat="_server"属性,js就变成asp的一部分了,你就可以直接调用了。
看参考资料