永发信息网

ASP写成JS

答案:6  悬赏:80  手机版
解决时间 2021-04-04 08:29
  • 提问者网友:两耳就是菩提
  • 2021-04-04 01:42
ASP写成JS
最佳答案
  • 五星知识达人网友:山君与见山
  • 2021-04-04 02:29
document.writeln("<% ");
document.writeln("if request.Cookies(\"godbook\")(\"shjianame\")<>\"\" then%> ");
document.writeln("<%=\"\"&request.Cookies(\"godbook\")(\"shjianame\")&\"<\/font>\"%> 您好,欢迎管理您的网上商城! <\/font> ");
document.writeln("<%end if%> ");
document.writeln(" ");
document.writeln("<%if request.Cookies(\"godbook\")(\"username\")=\"\" and request.Cookies(\"godbook\")(\"shjianame\")=\"\" then%> ");
document.writeln("亲爱的顾客您好,为保证商品及时准确送交,购买商品请先 [登录<\/a>] [注册<\/a>] ");
document.writeln("--->忘记密码?<\/a> <\/font> ");
document.writeln(" ");
document.writeln("<%elseif request.Cookies(\"godbook\")(\"username\")<>\"\" then ");
document.writeln("response.write request.Cookies(\"godbook\")(\"username\")&\" 欢迎来到本商城!\" ");
document.writeln("%> ");
document.writeln("");
document.writeln("<% ");
document.writeln("set rs=server.CreateObject(\"adodb.recordset\") ");
document.writeln("rs.open \"select count(*) as rec_count from shop_action where username=\'\"&request.Cookies(\"godbook\")(\"username\")&\"\' and zhuangtai=7\",conn,1,1 ");
document.writeln("rec_count=rs(\"rec_count\") ");
document.writeln("rs.close ");
document.writeln("rs.open \"select sum(zonger) as zongji from shop_action where username=\'\"&request.Cookies(\"godbook\")(\"username\")&\"\' and zhuangtai=7\",conn,1,1 ");
document.writeln("%> ");
document.writeln("您的购物车有 <%=rec_count%> <\/font>件商品 总金额:<%=rs(\"zongji\")%><\/font>元 ");
document.writeln(" 查看购物车\/结帐>><\/a> 我的收藏>><\/a> 进入会员中心<\/a> ");
document.writeln("<%end if%> ");
document.writeln("<\/font>");
document.writeln("");
全部回答
  • 1楼网友:三千妖杀
  • 2021-04-04 05:44
先给你讲讲应该怎么写,
如果要用js调用,那么你这个页面必须输入js代码,而不是直接输出html代码
在js中输出内容是用document.write("要输出的内容");
假设现在有一个hello.asp文件,我要在首页default.asp中用js调用他,并且显示“hello欢迎光临”
那么我应该这样做,
default.asp代码:





hello.asp代码:
document.write("hello欢迎光临");
这样,在访问default.asp页面时,就会看到“hello欢迎光临”
而在你的程序中,包含了一些asp和html代码,最方便的办法就是定义一个变量,然后将要输出的内容存放在这个变量中,如:
<%
dim outhtml
%>
然后将要输出的内容全部追加到这个outhtml变量上,最后输出,
<%
response.write("document.write('"& outhtml &"');")
%>
下面将详细的代码写出来,仅供你参考,不一定拿去就能运行,
草草写了一下,可能有错误,没有测试,你能看懂是什么意思就可以了。
<%
dim outhtml : outhtml =""
if request.Cookies("godbook")("shjianame")<>"" then
outhtml =""&request.Cookies("godbook")("shjianame")&" 您好,欢迎管理您的网上商城! "
end if
if request.Cookies("godbook")("username")="" and request.Cookies("godbook")("shjianame")="" then
outhtml =outhtml & "亲爱的顾客您好,为保证商品及时准确送交,购买商品请先 [登录] [注册]忘记密码? "
elseif request.Cookies("godbook")("username")<>""
outhtml =outhtml & request.Cookies("godbook")("username")&" 欢迎来到本商城!"
set rs=server.CreateObject("adodb.recordset")
rs.open "select count(*) as rec_count from shop_action where username='"&request.Cookies("godbook")("username")&"' and zhuangtai=7",conn,1,1
rec_count=rs("rec_count")
rs.close
rs.open "select sum(zonger) as zongji from shop_action where username='"&request.Cookies("godbook")("username")&"' and zhuangtai=7",conn,1,1
outhtml =outhtml &"您的购物车有 "& rec_count &" 件商品 总金额:"& rs("zongji") &"元"
outhtml =outhtml &"查看购物车/结帐>> 我的收藏>> 进入会员中心"
end if
response.write("document.write('"& outhtml &"');")
response.end
%>
  • 2楼网友:过活
  • 2021-04-04 04:33
楼主如果只是方便调用的话完全没必要写成JS,把这文件单独写在一个文件里,然后用包含进来就可以
或者把它写成一个函数
  • 3楼网友:有你哪都是故乡
  • 2021-04-04 03:55
晕,你这样用js写简直就是暴殄天物,让服务器的CPU多了一个指令。
  • 4楼网友:摆渡翁
  • 2021-04-04 03:30
Asp 代码保持不变 在 html 代码中用
document.writeln("html 代码");
起来
  • 5楼网友:渊鱼
  • 2021-04-04 02:45
楼上的又没有搞错啊,人家要的是js,你那叫js吗?分数有点少啊?整个程序都可以用js,包括数据库连接。
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯