【发布时间】:2021-06-03 16:14:55
【问题描述】:
我正在使用基本的 ASP,我想根据页面的 URL 显示两个图像之一。这是我最好的选择:
<%
Dim myURL
myURL = "https://www.domainname.com:443/Index.asp"
If myURL = "<% response.write(curPageURL()) %>" Then
response.write("<img src="img/image1-logo-150x50.png" width="150" height="50" alt="sitename">")
Else
response.write("<img src="img/image2-logo-80x80.jpg" width="80" height="80" alt="sitename">")
End If
%>
我卡住了,我的努力只能得到服务器错误 500 响应。任何见解将不胜感激。顺便说一句,我测试了<% response.write(curPageURL()) %>,它确实以我的代码中显示的格式检索了页面 URL。
根据 GSerg 的链接,我将代码更改为此,但它仍然不起作用:
<%
Dim myURL
myURL = "https://www.domainname.com:443/Index.asp"
If myURL = "<% response.write(curPageURL()) %>" Then
response.write("<img src=""img/image1-logo-150x50.png"" width=""150"" height=""50"" alt=""sitename"">")
Else
response.write("<img src=""img/image2-logo-80x80.jpg"" width=""80"" height=""80"" alt=""sitename"">")
End If
%>
也许我理解错了。
我已经使用 response.write 更正了错误,服务器现在运行代码;但是,条件不起作用。我对页面 URL 进行了写入测试以获取 curPageURL() 返回的格式,但是当我在应该显示 image1 的页面上时,它只显示 image2。这是我正在使用的:
<%
Dim myURL
myURL = "curPageURL()"
If myURL = "https://www.domainname.com:443/Index.asp" Then
response.write("<img src=""img/image1-logo-150x50.png"" width=""150"" height=""50"" alt=""name"">")
Else
response.write("<img src=""img/image2-logo-80x80.jpg"" width=""80"" height=""80"" alt=""name"">")
End If
%>
【问题讨论】:
-
这能回答你的问题吗? About using Double quotes in Vbscript
-
我从链接中得到的结论是,我必须在每个内部双引号集周围添加第二组双引号。我试过了,但没有用。
-
If myURL = "<% response.write(curPageURL()) %>" Then没有意义。你的意思是If myURL = curPageURL() Then? -
@GSerg 所说的是绝对正确的,你没有误解,但你也有
If myURL = "<% response.write(curPageURL()) %>" Then的问题,它永远不会工作。你不能在这样的If语句中使用Response.Write(),它永远不会起作用。相反,您需要将myURL字符串变量与我假设的包含当前页面curPageURL的字符串进行比较。 -
是的,GSerg,谢谢。我应该使用 If myURL = curPageURL() Then
标签: vbscript asp-classic