连接HTML

时间:2016-05-23 20:39:13

标签: javascript html json url

我正在构建使用JavaScript循环JSON对象的输出文本。一切都工作正常,直到我来到我需要为图像URL添加ID号的部分。我的图像存储在数据库中,我使用ASHX处理程序来加载图像,但我最终得到的并不是我需要的。

我最终需要的代码是Sub Initialize Dim session As New NotesSession Dim db As NotesDatabase Dim fileName As String Dim fileNum As Integer Dim headerstring As String Dim values As String Dim selection As String Dim collection As NotesDocumentCollection Dim doc As notesdocument On Error Resume Next Set db = session.CurrentDatabase Forall form In db.Forms If Isempty(form.Fields) Then Messagebox form.Name & " has no fields" Else 'Specify what form you want to export If form.Name = "Server Information" Then fieldCount = 0 msgString = "" fileNum% = Freefile() fileName$ = "c:\temp\LOTUS_EXPORT\" & form.Name & ".csv" Open FileName$ For Output As fileNum% Forall field In form.Fields msgString = msgString & Chr(10) & _ "" & field fieldCount = fieldCount + 1 headerstring=headerstring & |"| &field &|",| End Forall Write #fileNum%, |",| & headerstring & |"| headerstring="" Else End If End If selection = |Form="| & form.Name & |"| Set collection=db.Search(selection, Nothing, 0) For x = 1 To collection.count Set doc =collection.GetNthDocument(x) values="" Forall formfield In form.Fields Forall formfield.value != 'AdditionalDocumentation' newvalue=doc.GetItemValue(formfield) values=values & |"| & newvalue(0) & |",| End Forall End Forall Write #fileNum%, |",| & values &|"| values="" Next 'now check aliases If Isempty(form.Aliases) Then 'Messagebox form.Name & " has no aliases" Else Forall aliaz In form.Aliases If aliaz = form.Name Then Goto NextAliaz 'alias is same as form name End If selection = |Form="| & aliaz & |"| Set collection=db.Search(selection, Nothing, 0) For x = 1 To collection.count Set doc =collection.GetNthDocument(x) values="" Forall formfield In form.Fields newvalue=doc.GetItemValue(formfield) values=values & |"| & newvalue(0) & |",| End Forall Write #fileNum%, |",| & values &|"| values="" NextAliaz: Next End Forall End If Close fileNum% End Forall End Sub
但我得到的是~/ImageHandler.ashx?id=35。 ID周围有单引号。

我知道这是~/ImageHandler.ashx?id='35'"的语法。

我试过的是

""

以及不起作用的每种组合。

如果我没记错的话,我需要三重单引号或双引号的组合或两者的某种组合。 myOutput += "<img src ='~/ImageHandler.ashx?id='" + ID + class='person-image'></img>" 是从JSON对象读取的整数。

提前致谢

1 个答案:

答案 0 :(得分:1)

您可以使用转义字符\

添加双引号
myOutput += "<img src=\"~/ImageHandler.ashx?id="  + ID  + "\" class=\"person-image\"></img>" 

这将附加

<img src="~/ImageHandler.ashx?id=35" class="person-image"></img>