在具有可变输出的 VBscript 数组中创建超链接



努力挽回这个问题:更新了下面的编辑。

<%
doMenu
    dim products
    dim manu
    dim website
    products = Array("E-reader set: Kindle Paperwhite, $119","Leather tote, $160","Earrings, $88","Skin care duo: Moisturizer, $62","Throw pillow, $90","Vitamix 5200, $449","Tea set: Le Creuset kettle, $1oo","Spring nail polish collection, $51","Framed birthstone print, $48","Cotton robe, $25","Jewelry box, $49","Water bottle, $35","Polka-dot scarf, $38","Makeup set: Eye palette, $44","Sequin pouch, $88","Ceramic set: Jar, $22","Honeycomb perfume, $54","3-jar jam set, $24","Recipe box, $34","Hair dryer, $200","Epicurious 11-piece cookware set, $320","Cookbook collection: 100 Days of Real Food by Lisa Leake, $20","Threshold dining set: Placemats, $10","Sodastream genesis, $90","Alexia necklace, $49","Wild & wolf garden tool set, $33","Rattan floor basket, $59","Olivia burton watch, $105","Yoga set: Mat, $40","Hair-care system: Restore shampoo, $28","")
    manu = Array("leather case, $40","","","eye serum, $48","","","three organic tea blends, $50","","","","","","","lip palette, $40; brush set, $50","","mug, $18; tray, $15","","","","","","Twelve Recipes by Cal Peternell, $20; Better on Toast by Jill A. Donenfeld, $20","$10; napkins","","","","","","bag, $20; towel, $25","conditioner, $28; mask treatment, $4","")
    website = Array("www.amazon.com","www.baggu.com","www.sarahhealydesign.com ","www.kiehls.com","www.Laylagrayce.com","www.vitamix.com","www.williams-sonoma.com","www.essie.com","www.minted.com","www.worldmarket.com","www.westelm.com","www.swellbottle.com","www.echodesign.com","www.maccosmetics.com","www.bodenusa.com","www.rosannainc.com","www.libraryofowers.com","www.murrayscheese.com","www.rifepaperco.com","www.shopt3micro.com","www.jcpenney.com", "www.amazon.com", "www.target.com", "www.surlatable.com","www.stelladot.com","www.burkedecor.com","www.landofnod.com","www.modcloth.com","www.gaiam.com","www.livingproof.com","")
%>

上面的代码填充单个动态单页网站中的内容部分。问题是网站只输出复制/文本URL。我需要它链接,最好是链接 target="_blank"新窗口。我已经尝试了以下方法;通过一个回答的建议 - 虽然我认为这可能是更好的做法,但它似乎不与其他数组一起运行,并且破坏站点以仅解析为白页。我尝试将其包含在同一包含中的其他数组结构中,并分离并破坏站点。我还arrUrls的名称切换为website并声明暗淡arrUrls等,一切都破坏了页面,所以仍然需要一个解决方案。

dim arrUrls
arrUrls = Array("www.amazon.com","www.baggu.com")
For x=0 To UBound(arrUrls)
    currentUrl = arrUrls(x)
    Response.Write("<a href=""http://""" & currentUrl & """ target=""_blank"">" & currentUrl & "</a>")
Next

过去,我已经使用jQuery数组完成了下面的工作,并且希望使用类似的解决方案,因为内联和清晰易读的东西将是完美的。

     { value: "NYC", url: 'http://www.nyc.com' }, 
     { value: "LA", url: 'http://www.la.com' },
     { value: "Philly", url: 'http://www.philly.com' },

不会在数组中创建超链接。您可以在迭代数组的代码中创建它们:

<%
    Dim arrUrls, x, currentUrl
    arrUrls = Array("www.amazon.com","www.baggu.com")
    For x=0 To UBound(arrUrls)
        currentUrl = arrUrls(x)
        Response.Write("<a href=""http://" & currentUrl & """ target=""_blank"">" & currentUrl & "</a>")
        If x < UBound(arrUrls) Then Response.Write(" | ")
    Next
%>

就这么简单。

<a href="http://<% response.write(website(day_part-1))%>" target="_blank" ><% response.write(website(day_part-1))%></a>

仅包括具有可变输出的内联是最佳和功能最强大的。仅此代码,内联;无需更改数组。

用大锤敲开螺母:

Class LinkBuilder
'You could go with a dictionar or other name/value pair collection
'But we will keep this simple-ish
  Public Href
  Public Target
  Public CssClass
  Public Style
  Public Rel
  Public Id
  Public SetLink (iHref, iTarget, iClass, iStyle, iRel, iID)
       Href = iHref
       Target = iTarget
       CssClass = iClass
       Style = iStyle
       Rel = iRel
       Id = iID
  End Function
  Public GetOpenATag()
       Dim output;
       output = "<a href='" & Href & "'"
       if Target is not null and Target <> '' then
          output = output & " target='" & Target & "'"
       end if
       if Id is not null and Id <> '' then
          output = output & " id='" & Id & "'"
       end if
        'YOu get the Idea... do the same for the other properties
       output = output & " >" 
  End Function
End Class
'Now build your array of links 
Dim arrLinks()
arrLinks(0) = new LinkBuilder.SetLink("www.amazon.com", "_blank", "external", null, null, null)
arrLinks(1) = new LinkBuilder.SetLink("www.baggu.com", null, null, null, null, null)
'now to get a link
Dim aLink = arrLinks(0).GetOpenATag() & "Amazon</a>"

这是一个非常粗略的轮廓,完全未经测试。但是,它应该为您提供一些可以使用的东西。还要调查 Asp 字典对象。

最新更新