Vbscript HTA,动态生成带有onclick错误的HTML表

Vbscript HTA,动态生成带有onclick错误的HTML表,vbscript,onclick,html-table,hta,Vbscript,Onclick,Html Table,Hta,对。我需要帮助。我有一个HTA,运行完全正常。直到我对代码执行以下操作。我正在使用VBScript。代码如下: <Script language="vbscript"> Sub DisplayDB_Click Dim conn, str1, str2 str2 = "Hello" MainTitle.InnerHTML = "<h2>Main Call Queue</h2>" Set conn = CreateObject("ADODB.Co

对。我需要帮助。我有一个HTA,运行完全正常。直到我对代码执行以下操作。我正在使用VBScript。代码如下:

<Script language="vbscript">

Sub DisplayDB_Click
  Dim conn, str1, str2
  str2 = "Hello"
  MainTitle.InnerHTML = "<h2>Main Call Queue</h2>"
  Set conn = CreateObject("ADODB.Connection")
  conn.Open "DSN=LongbowLogin"
  Set rsData = conn.Execute("SELECT * FROM MainTable WHERE CallStat='Open' ORDER BY P_ID DESC;")
  str1 = "<table border=1 cellpadding=5><tr><th>Call Id</th><th>Full Name</th><th>Postcode</th><th>Site Code</th><th>Problem Title</th><th>Category</th><th>SubCategory</th><th>Call Status</th></tr>"
  Do Until rsData.EOF = True
    str1 = str1 & "<tr><td onclick=msgbox(str2)>" & rsData("P_Id") & "</td><td>" & rsData("FirstN") & "</td><td>" & rsData("PostCode") & "</td><td>" & rsData("SiteNumber") & "</td><td>" & rsData("PTitle") & "</td><td>" & rsData("PCat") & "</td><td>" & rsData("SCat") & "</td><td>" & rsData("CallStat") & "</td></tr>"
    rsData.moveNext
  Loop
  str1 = str1 & "</table>"
  MainDisplay.InnerHTML = str1
  conn.Close
  Call CheckState
End Sub

子显示单击
Dim conn、str1、str2
str2=“你好”
maintTitle.InnerHTML=“主呼叫队列”
Set conn=CreateObject(“ADODB.Connection”)
连接打开“DSN=LongbowLogin”
设置rsData=conn.Execute(“从主表中选择*,其中CallStat='Open'按P_ID DESC;排序”)
str1=“调用IdFull-NamePostCodes站点代码问题标题类别子类别调用状态”
直到rsData.EOF=True为止
str1=str1&&rsData(“P_Id”)&&rsData(“FirstN”)&&rsData(“邮政编码”)&&rsData(“站点号”)&&rsData(“PTitle”)&&rsData(“PCat”)&&rsData(“SCat”)&&rsData(“CallStat”)&&
rsData.moveNext
环
str1=str1&“
main display.InnerHTML=str1
关闭连接
呼叫检查状态
端接头
这段代码使用SQL Select语句生成一个HTML表,并将其放置在名为
main display
的Span标记中
InnerHTML
下。这部分做得很好。但是-在我添加
部分,它将无法工作

我单击第一个单元格,得到一条消息:
“第1行,'str2'未定义。”

我真的想让它说
CellID
是同一脚本块后面的子脚本。我这样做是为了排除故障

str2
已经明确定义,所以我显然遗漏了一些东西

这里的任何帮助都会很好,我快疯了


非常感谢。

VBScript不进行变量插值:

>> Dim str2 : str2 = "I'm str2 and this is my content"
>> Dim sRes : sRes = "<td onclick=MsgBox str2></td>"
>> WScript.Echo sRes
>>
<td onclick=MsgBox str2></td>
>Dim str2:str2=“我是str2,这是我的内容”
>>Dim sRes:sRes=“”
>>Echo sRes
>>
您必须将内容拼接到结果中,并遵循VBScript关于括号和引号的规则:

>> Dim str2 : str2 = "I'm str2 and this is my content"
>> Dim sRes : sRes = "<td onclick='MsgBox """ & str2 & """'></td>"
>> WScript.Echo sRes
>>
<td onclick='MsgBox "I'm str2 and this is my content"'></td>
>Dim str2:str2=“我是str2,这是我的内容”
>>Dim sRes:sRes=“”
>>Echo sRes
>>

VBScript不执行变量插值:

>> Dim str2 : str2 = "I'm str2 and this is my content"
>> Dim sRes : sRes = "<td onclick=MsgBox str2></td>"
>> WScript.Echo sRes
>>
<td onclick=MsgBox str2></td>
>Dim str2:str2=“我是str2,这是我的内容”
>>Dim sRes:sRes=“”
>>Echo sRes
>>
您必须将内容拼接到结果中,并遵循VBScript关于括号和引号的规则:

>> Dim str2 : str2 = "I'm str2 and this is my content"
>> Dim sRes : sRes = "<td onclick='MsgBox """ & str2 & """'></td>"
>> WScript.Echo sRes
>>
<td onclick='MsgBox "I'm str2 and this is my content"'></td>
>Dim str2:str2=“我是str2,这是我的内容”
>>Dim sRes:sRes=“”
>>Echo sRes
>>

要使
MsgBox
正常工作,您必须更改以下内容:

"<tr><td onclick=msgbox(str2)>" & rsData("P_Id") & ...

要使
MsgBox
正常工作,您必须更改以下内容:

"<tr><td onclick=msgbox(str2)>" & rsData("P_Id") & ...

好的,我明白你的意思,我想。。。我以为VBScript不允许使用“WScript.Echo”命令?另外,您能否给出一个示例,说明如何使用DOM命令来实现这一点?非常感谢。那么这个问题还有其他解决办法吗?使用JavaScript的glup呢?谢谢…好吧,我明白你的意思,我想。。。我以为VBScript不允许使用“WScript.Echo”命令?另外,您能否给出一个示例,说明如何使用DOM命令来实现这一点?非常感谢。那么这个问题还有其他解决办法吗?使用JavaScript的glup呢?谢谢…好的,上面,你用的是Div标签,我用的是Span标签,有什么区别吗?好的,好的,我要放弃这个。我不能让它工作。它继续说“期待”;“。我不知道它与MySql语句的交互是否很糟糕,或者是什么。我采用了新的方式来处理表,每个字段的
部分工作得更好-谢谢。我已经制定了一个解决方案。它没有那么漂亮,但很有效。不好意思……不管是谁,从现在开始。
是块级元素,而
是块级元素。”一个内联元素(不应该(ab)用作块级元素)。我的示例代码同时使用
。至于
预期值”;“
错误:我已经告诉过你,这可能是由包含非JavaScript代码的
块引起的。为了进一步排除故障,你需要提供HTA的完整代码。好的-上面,你使用了Div标记,我使用的是Span标记,有什么区别吗?好的,好的,我打算放弃这个。我无法得到这个工作。”它继续说“期待”;“。我不知道MySql语句的交互是否很糟糕,或者是什么。我采用了一种新的方法来制作表格,每个字段的
部分工作得更好,谢谢。我已经准备好了解决办法。虽然没那么漂亮,但它很管用。羞愧。。。anywho,forwards.
是块级元素,而
是内联元素(不应(ab)用作块级元素)。不过,我的示例代码同时适用于
。至于
expected”;“
错误:我已经告诉过你,它可能是由包含非JavaScript代码的
块引起的。为了进一步排除故障,您需要提供HTA的完整代码。
<p><input type="button" onClick="DisplayDB_Click" value="Show Table"/></p>
<div id="MainDisplay"></div>
Sub Cell
  MsgBox Me.innerHtml
End Sub

Function NewField(text, isHeader)
  If isHeader Then
    Set e = document.createElement("th")
  Else
    Set e = document.createElement("td")
  End If
  e.AppendChild document.createTextNode(text)
  e.onClick = GetRef("Cell")
  Set NewField = e
End Function

Function NewRow(values, isHeader)
  Set r = document.createElement("tr")
  For Each v In values
    r.appendChild NewField(v, isHeader)
  Next
  Set NewRow = r
End Function

Sub DisplayDB_Click
  ...

  lastCol = rsData.Fields.Count-1
  Dim cols
  ReDim cols(lastCol)

  For i = 0 To lastCol
    cols(i) = rsData.Fields(i).Name
  Next

  Set thead = document.createElement("thead")
  thead.appendChild NewRow(cols, True)

  Set tbody = document.createElement("tbody")
  Do Until rsData.EOF
    For i = 0 To LastCol
      cols(i) = rsData.Fields(i).Value
    Next
    tbody.appendChild NewRow(cols, False)
    rsData.MoveNext
  Loop

  Set table = document.createElement("table")
  table.appendChild thead
  table.appendChild tbody
  document.getElementById("parent").appendChild table

  ...
End Sub