Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/401.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 对元素使用querySelector时未定义或为null_Javascript - Fatal编程技术网

Javascript 对元素使用querySelector时未定义或为null

Javascript 对元素使用querySelector时未定义或为null,javascript,Javascript,以下是我单击的按钮: <a href="#" id="toggle|313746669218847_314159322510915" class="comment-reply comment-reply-default" role="button"> <i class="fa fa-reply" aria-hidden="true"></i> <span>Reply</span> </a> 运行上述行后,reply

以下是我单击的按钮:

<a href="#" id="toggle|313746669218847_314159322510915" class="comment-reply comment-reply-default" role="button">
  <i class="fa fa-reply" aria-hidden="true"></i>
  <span>Reply</span>
</a>
运行上述行后,
replyElement
中的结果HTML代码段:


虚拟页面

2018-11-28 07:17下午

发送
很可能您的
replyElement
不存在,因为使用
querySelector
查找文本区域有效:

我只能猜测你的身份证应该是什么,但这是可行的:

const replyElement=document.getElementById('toggle | 313746669218847_314159322510915')。parentElement.parentElement;
var myElement=replyElement.querySelector('.reply_text_area');
console.log(myElement)

虚拟页面

2018-11-28 07:17下午

| 你好,T

发送
您没有
id=some id的元素
。如果JS不起作用,则返回第一行。提供一个真正的@Quentin-Well首先,当我编写代码片段replylement时,我还发布了我在replylement中得到的结果代码片段。我不知道你为什么要编辑它,提供一个真正的@HVenom如果你通过它的
id
选择一个元素,然后得到它的父元素,那么这个
id
的元素应该在父元素中。对你来说不是。如果我将该id添加到
虚拟页面周围的
中,那么我就可以很好地恢复元素。如果没有,我们就帮不了你。@Quentin编辑已经完成了Well这正是问题所在
myElement
给了我空值或未定义的值你的代码和我答案中的代码片段有什么区别?
const replyElement = document.getElementById("toggle|313746669218847_314159322510915").parentElement.parentElement;