在vb.net中将多个变量传递给javascript onclick

时间:2015-05-26 08:19:12

标签: javascript vb.net

我试图通过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 & "&nbsp;</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 & "&nbsp;</font></a>"
    ElseIf skillDetail.ForeColor <> "" Then
        td.Text += "<a href='#' onclick='EndSkill(" & empDetail.EmployeeId & "," & skillDetail.SkillCode & ");'><font color=""" & skillDetail.ForeColor & """>" & skillDetail.SkillCode & "&nbsp;</a>"
    Else
        td.Text += "<a href='#' onclick='EndSkill(" & empDetail.EmployeeId & "," & skillDetail.SkillCode & ");'><font color=""black"">" & skillDetail.SkillCode & "&nbsp;</font></a>"
    End If

Next
td.Text += "<a href='#' onclick='AddSkill(" & empDetail.EmployeeId & ");'><font color=""green"">+&nbsp;</font></a>"
tr.Cells.Add(td)

1 个答案:

答案 0 :(得分:2)

经典引号问题,您应该将empDetail.EmployeeIdskillDetail.SkillCode与引号一起传递,以作为字符串参数处理。否则它们将被视为变量,显然你没有定义,因此会得到错误。

我在这里找到了报价

td.Text += "<a href='#' onclick='EndSkill(""" & empDetail.EmployeeId & """,""" & skillDetail.SkillCode & """);'>"

在VB中转义双引号是将双引号加倍: