我试图通过vb.net中的javascript方法onclick传递id和代码。我收到错误'示例字符串'未定义。所有其他变量都会毫无问题地通过。也许我的语法错了。我不确定。
For Each skillDetail As StationEmployeSkill In empDetail.EmployeeSkills
If skillDetail.IsExpired And GlobalsFSiA.HighlightSkillsAfterExpiring > -1 Then
td.Text += "<a href='#' onclick='EndSkill(" & empDetail.EmployeeId & "," & skillDetail.SkillCode & ");'><font color=""red"">" & skillDetail.SkillCode & " </font></a>"
ElseIf skillDetail.ExpiresSoon And GlobalsFSiA.HighlightSkillsBeforeExpiring > -1 Then
td.Text += "<a href='#' onclick='EndSkill(" & empDetail.EmployeeId & "," & skillDetail.SkillCode & ");'><font color=""blue"">" & skillDetail.SkillCode & " </font></a>"
ElseIf skillDetail.ForeColor <> "" Then
td.Text += "<a href='#' onclick='EndSkill(" & empDetail.EmployeeId & "," & skillDetail.SkillCode & ");'><font color=""" & skillDetail.ForeColor & """>" & skillDetail.SkillCode & " </a>"
Else
td.Text += "<a href='#' onclick='EndSkill(" & empDetail.EmployeeId & "," & skillDetail.SkillCode & ");'><font color=""black"">" & skillDetail.SkillCode & " </font></a>"
End If
Next
td.Text += "<a href='#' onclick='AddSkill(" & empDetail.EmployeeId & ");'><font color=""green"">+ </font></a>"
tr.Cells.Add(td)
答案 0 :(得分:2)
经典引号问题,您应该将empDetail.EmployeeId
和skillDetail.SkillCode
与引号一起传递,以作为字符串参数处理。否则它们将被视为变量,显然你没有定义,因此会得到错误。
我在这里找到了报价
td.Text += "<a href='#' onclick='EndSkill(""" & empDetail.EmployeeId & """,""" & skillDetail.SkillCode & """);'>"
在VB中转义双引号是将双引号加倍: