为什么我的ASP函数没有返回A Href内的链接?

时间:2015-04-17 08:25:16

标签: asp-classic

早上好,

我目前正在编写经典ASP功能来修改URL,但添加了产品名称以增强链接强度。我设法让链接正确,但它没有放在HREF中,它显示为URL。

为了更好地解释这一点,请参阅以下示例:

看看第一类输出: http://www.dibor.co.uk/sitemap.asp

功能:

function URLName(var1,var2)
    dim nameString
    dim scString
    scString = UCase(var2)
    nameString = var1
    nameString = Replace(nameString," ","-")
    nameString = Replace(nameString,"'","")
    nameString = Replace(nameString,"!","")
    nameString = Replace(nameString,"&","and")
    varString = LCase(nameString)
    response.write("http://www.dibor.co.uk/Product.asp?ProductId=" & scString & "&title=" & varString)
end function

输出代码:

Response.Write "<li><a href='" & 
    URLName(LivingRoomFurniture.fields("ProductTitle"), 
    LivingRoomFurniture.fields("StockCode")) & "'>" & 
    LivingRoomFurniture.fields("ProductTitle") & "</a> - " & 
    FormatCurrency(LivingRoomFurniture.fields("Price"),2) &"</li>"

1 个答案:

答案 0 :(得分:2)

要从函数返回值,请将其指定给函数名称;在函数中使用response.write在输出代码执行之前写出URL。换句话说,您的修复应该是:

function URLName(var1,var2)
    dim nameString
    dim scString
    scString = UCase(var2)
    nameString = var1
    nameString = Replace(nameString," ","-")
    nameString = Replace(nameString,"'","")
    nameString = Replace(nameString,"!","")
    nameString = Replace(nameString,"&","and")
    varString = LCase(nameString)
    URLName = "http://www.dibor.co.uk/Product.asp?ProductId=" & scString & "&title=" & varString
end function