这是我的html
<td>
<input type="text" name="FullName"/>
<img/>
</td>
我正在尝试通过以下方式获取图像元素。但是,它不起作用-
var form = document.forms["myform"];
var fullNameTextBox = form["FullName"];
var thisImage = fullNameTextBox.nextSibling;
thisImage.style.display = 'block'; //shows uncaught type error,can not set property display of undefined.
有什么帮助吗?
最佳答案
你必须使用 nextElementSibling
var form = document.forms["myform"];
var fullNameTextBox = form["FullName"];
var thisImage = fullNameTextBox.nextElementSibling;
thisImage.style.display = 'block';
关于javascript - 获取输入 javascript 的下一个 img 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29730699/