使用JScript提取HTML表格选中行数值并传递给VBScript求助
我刚接触HTML和JS,目前在为实验室计算机开发相关功能。我从Stack Overflow的两个已有问答整合了代码,但未能达到预期效果。
需求说明
让用户从表格的多行数据中进行选择,选中行的数据会在页面下方展示供用户确认,最终需要将这些参数传递给为Biomek液体处理平台编写的VBScript主程序。
待传递的变量是主程序的全局变量,但主程序无法识别行选中操作带来的变量变更。无论我如何调试,要么完全无法获取变量,要么拿到的是字符串格式(我需要数值格式),要么只能为变量赋值字符串名而非对应的实际数值。
存在问题的代码
<html> <head> <style> table, th, td { border: 1px solid black; border-collapse: collapse; } </style> <script language="javascript" type="text/javascript"> function showRow(row) { var x=row.cells; document.getElementById("Volume1").value = x[0].innerHTML; document.getElementById("Volume2").value = x[1].innerHTML; } function ChangeColor(row, highLight) { if (highLight) { row.style.backgroundColor = '#dcfac9'; } else { row.style.backgroundColor = 'white'; } } </script> </head> <body> <FORM METHOD="GET" ACTION="http://localhost"> <table id="myTable" cellspacing="3" <thead> <tr> <th>Volume 1</th> <th>Volume 2</th> </tr> </thead> <tbody> <tr onclick="javascript:showRow(this);" onmouseover="javascript:ChangeColor(this, true);" onmouseout="javascript:ChangeColor(this, false);" > <td>88.4</td> <td>100</td> </tr> <tr onclick="javascript:showRow(this);" onmouseover="javascript:ChangeColor(this, true);" onmouseout="javascript:ChangeColor(this, false);" > <td>22.8</td> <td>44</td> </tr> <tr onclick="javascript:showRow(this);" onmouseover="javascript:ChangeColor(this, true);" onmouseout="javascript:ChangeColor(this, false);" > <td>73.2</td> <td>125</td> </tr> <tr onclick="javascript:showRow(this);" onmouseover="javascript:ChangeColor(this, true);" onmouseout="javascript:ChangeColor(this, false);" > <td>13.64</td> <td>17</td> </tr> </tbody> </table> <br> <br> Volume 1 is:<input type="text" id="Volume1" /> <br> Volume 2 is:<input type="text" id="Volume2" /> <br> <br><br><br> <INPUT TYPE="submit" NAME="submitButton__" VALUE="CONTINUE" /> </FORM> </body> </html>
此前成功实现的参考代码
此前我已经完成过类似功能,下方代码片段中,主程序可以正常读取user_NumberSamples、user_Replicates、user_DiluteSample三个变量的值,但当前使用场景存在差异:
<HTML> <HEAD> <SCRIPT LANGUAGE="VBScript"> <!-- ***** Put scripts for handling page elements here --> </SCRIPT> <BODY BGCOLOR="BlanchedAlmond"> <FORM METHOD="GET" ACTION="http://localhost"> <h1 style="text-align:center;">TEST METHOD</h1> <TABLE BOARDER=1> <TR> <P><h3 style="text-align:center;">Please enter all of the required information</h3></TD> </P> <BR> <p> </p> <TR> <TR><strong>Enter the number of samples being tested: </strong></TR> <TR><INPUT TYPE=text NAME="user_NumberSamples" SIZE=2 VALUE="48"> </TR> <br> <br> <p> <TR><strong>Please select the number of REPLICTES: </strong><TR> <select name="user_Replicates" size="1"> <option>3</option> <option>2</option> <option>1</option> </select></BR> <TR> </TABLE> <br> <tr><strong>Perform a pre-dilution of Samples 1:10?:</strong></tr> <input type="radio" id="False" name="user_DiluteSample" value="False" checked> <label for="False">False</label> <input type="radio" id="True" name="user_DiluteSample" value="True"> <label for="True">True</label><br> <p>NOTE: Diluting samples will make all replicates come from the same dilution plate, i.e. technical replicates<p> <INPUT TYPE="submit" NAME="submitButton__" VALUE="Click To Continue"> </FORM> </BODY> </HTML>
我已经花费大量时间调试但仍未解决问题,特此向各位专家求助,感谢!
内容的提问来源于stack exchange,提问作者Brad Meyer
相关产品推荐
相关产品推荐

