javascript - 获取输入 javascript 的下一个 img 元素

标签 javascript

这是我的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/

相关文章:

javascript - 如何让这个嵌套函数挑战问题在 JavaScript 中发挥作用?

php - 如何显示来自其他站点的 RSS 提要

javascript - 选择第一个非空的 span 元素

javascript - 创建 json 对象以排除未定义的属性

javascript - 为什么 document.execCommand ('' backColor'') 不适用于 css 变量,而 foreColor 可以?

用于匹配正则表达式的 Javascript 正则表达式

javascript - 不同文件之间的吊装

javascript - & 符号获取子级/父级集合

javascript - 跨度未显示在图像 slider 中

javascript - 为什么这个 JSON 显示为未定义?