无法使用getElementById
Not work with getElementById
本文关键字:getElementById 更新时间:2023-09-26
getElementById("VAL5"+i)无效。然后input3没有运行
我希望有了这个代码足够的信息来提供
错误在行的某个位置
/*数字输入*/
index=输入2_off对于(i=0;i<4;i++)getElementById("VAL5"+i).src=valueArray[input2_offs[i]]=="0"?'gif/dot_red.gif':'gif/dot_gr.gif'
问题在哪里
enter code here
<!--
var req = null;
req = AjaxInit();
var PostBuffer = new Array;
var Trace;
/* number of channels per sensor input type */
var InputChannels = 4; /* max 4 digital inputs */
var names = new Array();
var units = new Array();
var offs = new Array();
var gain = new Array();
var value = new Array();
var input2_offs = 25;
var input3_offs = 26;
/*
this function is called on body load and later every 5s
request a new set of data from the controller
*/
function UpDate()
{
var x = Math.random()*1000; /* add random number to the url to avoid caching the content in the browser */
x=x.toFixed(3);
AjaxGetRequest("/GetState.csv"+"?a="+x,UpdateTraceBuffers);
return false;
}
/*
call back routine when the controller has send the data
this function separates all items in separate arrays as :
names, units, offsets , gains and the raw values
*/
function UpdateTraceBuffers()
{
Trace = req.responseText.split(''n');
names = Trace[TraceNameOffs].split(',');
units = Trace[TraceUnitOffs].split(',');
offs = Trace[TraceOffs].split(',');
gain = Trace[TraceGain].split(',');
value = Trace[TraceDataoffs].split(',');
UpdateWebSite(); /* user routine , update all items */
if(timerHandle == 0)
{
timerHandle = window.setInterval("UpDate()", 5000);
}
}
/* DigitalInput */
index = input2_offs;
for(i=0;i<4;i++)
getElementById("VAL5"+i).src = valueArray[input2_offs[i]] == "0" ? 'gif/dot_red.gif' : 'gif/dot_gr.gif';
index = input3_offs;
v = (parseFloat(offs[index]) + parseFloat(gain[index])* parseFloat(value[index])).toFixed(0);
getElementById("SENS_VAL6").innerHTML = v;
//-->
<td class="mytd"><div align="center"><img src="gif/dot_red.gif"
width="24" height="24" id="VAL5"></div></td>
<td id="SENS_VAL6" class="mytd" align="right"> </td>
document.getElementById("VAL5"+i);
或者你可以使用:
document.querySelector("VAL5"+i)
适用于所有现代浏览器(IE8+)。https://developer.mozilla.org/en-US/docs/Web/API/document.querySelector
实际上,在循环和if语句等中使用{},这是js中的一种推荐做法。
相关文章:
- reactjs this.refs vs document.getElementById
- 如何通过adf中的document.getElementById获取inputText字段值
- 无法获取文档.GetElementById工作正常
- document.getElementById(“st”).click();不起作用
- Javascript:Can't使用getElementById获取元素
- 如何使用“;getElementById”;在一个循环中
- Javascript GetElementByID has no value
- document.getElementById并使用id名称
- document.getElementById在js中不起作用
- document.getElementById.style.backgroundImage not working
- 如何从document.getElementById()中获取UniqueID
- 从输入框、Javascript、getElementById获取值
- 什么'这个javascript代码getElementById有问题
- DOMDocument getelementbyid conflict?
- 如何从getelementbyid用javascript编写变量
- inline svg--getElementById在Opera中不起作用
- 在init function()中调用getElementById(“..”),而不是想用它做点什么的函数
- 将global.getelementbyid连接到单个变量中
- 未捕获的类型错误:未定义不是上的函数.GetElementByID
- document.getElementById(..) is null