简体   繁体   English

将数据从 HTML 传递到 JS 函数

[英]Passing data from HTML to JS function

I have a series of data points that I query for status and voltage, and want to use a function to display as readable data in a table .我有一系列数据点,用于查询状态和电压,并希望使用函数在表格中显示为可读数据

I can't seem to get how to pass the register data to the fnction , and then return the processed data to the table .我似乎不明白如何将寄存器数据传递给 fnction ,然后将处理后的数据返回到 table

Here's the test code,下面是测试代码

<input type="hidden" id="reg120" name="reg120" readonly value="%d">
<input type="hidden" id="reg121" name="reg121" readonly value="%d">

<script language="javascript">

function dsestate(regn) {

    var state = ["STOP MODE","AUTO MODE","MANUAL MODE","TEST ON LOAD","AUTO MAN","USER CONF","TEST OFF LOAD","OFF"];
    return state[regn];
    }

</script>

<script language="javascript">

function divby10(regn1) {
    return regn1/10;
    }   

</script>

<table id="maintable" style="width:75%">

  <tr>
    <th>Site</th>
    <th style="width:180px">Status</th> 
    <th style="width:180px">Voltage</th>

   </tr>
   <tr> 
    <td><input type="text" id="dsestate(reg120)"></td>
    <td><input type="text" id="divby10(reg121)"></td>
   </tr>




</table>

</body>
</html>

Any help would be appreciated.任何帮助,将不胜感激。

divBy10's argument should be a number (so it could be divided by 10). divBy10 的参数应该是一个数字(所以它可以被 10 整除)。 dsestate's argument should also be a number so you can get the object by the index of the state Array (ie state[1]). dsestate 的参数也应该是一个数字,以便您可以通过状态数组的索引(即 state[1])获取对象。

And since you're calling a javascript function, it should also use onload=, rather than id=.并且由于您正在调用一个 javascript 函数,它也应该使用 onload=,而不是 id=。

I hope that gives you a starting point, good luck!我希望这能给你一个起点,祝你好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM