javascript无法读取属性'style'为null
javascript cannot read property 'style' of null
此功能应该隐藏患者备注并显示下一个备注(如果他们有另一个备注)
function nextNote(idno){
document.getElementById(idno).style.display = 'none';
var idno2 = parseInt(idno)+1;
document.getElementById(idno2.toString()).style.display = 'inline';
document.getElementById('prevNote').label = parseInt(document.getElementById('prevNote').label) + 1;
document.getElementById('nextNote').label = parseInt(document.getElementById('nextNote').label) + 1;
未捕获的类型错误:无法在"document.getElementById(idno).style.display = 'none';
读取null的属性"style"
有问题的元素<li class="notes" label="1052" style="display: inline;" id="1">On: 5/17/2004 A real good Patient test</li>
nextNote由调用:<input type="button" id="nextNote" class="notesbottombutton" value=">" label="1" onclick="nextNote(this.label);" />
如果我使用Chrome javascript控制台document.getElementById(1).style.display;
我得到:"inline"
注意,我会在函数工作后添加检查,例如if(document.getElementById(idno2.toString()),这样如果没有更多的注释显示,它就不会做任何事情,我只是试图首先获得基本功能
也许问题出在您的点击处理程序:
nextNote(this.label);
label
不是HTML输入的属性。它甚至不是一个有效的属性。要用type="button"
设置input
的标题,您应该使用其value
属性并使用this.value
来访问它。
如果您只是使用该属性将数据附加到元素,并希望访问该属性,则应该这样做:
nextNote(this.getAttribute('label'));
但我建议您使用前缀为data-
的属性,这是在HTML5中附加数据的标准方式(它也向后兼容):
<input data-label="foo" />
nextNote(this.getAttribute('data-label'));
this.label
引用元素上的label属性,但您正在设置一个名为label的属性。将您的onclick更改为:
onclick="nextNote(this.getAttribute('label'));"
- 数组在递归方法中设置为null
- javascript无法读取属性'style'为null
- 无法在Chrome的Javascript控制台中读取null的属性“style”
- JavaScript TypeError:无法读取 null 的属性“style”
- 未捕获的类型错误:无法读取属性'style'为null
- 如何修复未捕获的类型错误:无法读取属性'style'为null
- 未捕获的类型错误:无法读取属性'style'为null
- 0.style为null或不是aobject
- HTML已创建,但style = null
- 未捕获的TypeError: Cannot read property 'style'null - JS
- TypeError: Cannot read property 'style' of null (Jav
- Webview:无法读取property 'style'null +意外标识符
- 未捕获类型错误:无法读取属性'style'null"
- TypeError: null不是对象(计算'document.getElementById(x).style&
- 不能读取属性'style'动态HTML代码中的null
- 未捕获的类型错误:无法读取属性'style'为null
- 道场'TypeError:无法读取属性'style'为null的'发送xhrPost请求
- Simon.js:未捕获类型错误:无法读取属性'style'为null
- JS 类型错误:无法读取 null 的属性“style”
- TypeError: Cannot read property 'style' of null in j