简体   繁体   English

document.getElementById()不断返回NULL-如何查找值

[英]document.getElementById() keeps returning NULL - how to find value

I am using one of those vulnerable practice sites on Kali Linux and when I inspected the source page I noticed the following variable var pathName = document.getElementById("path") The value of pathName is hidden and it is up to me to find it as these sites are there for people to practice their ethical hack skills 我正在Kali Linux上使用那些易受攻击的练习站点之一,当我检查源代码页面时,我注意到以下变量var pathName = document.getElementById("path") pathName的值是隐藏的,要我自己找到它因为这些网站供人们练习道德操守技能

So in the Chrome Web Browser console, I type in document.getElementById("path").value but I keep getting return null . 因此,在Chrome Web浏览器控制台中,我输入document.getElementById("path").value但我一直得到return null I don't understand why, like do I need to do like window.ontop ? 我不明白为什么,就像我需要像window.ontop一样?

Any help would be great! 任何帮助将是巨大的!

If document.getElementById("path").value returns null, your element was found. 如果document.getElementById("path").value返回null,则找到您的元素。 It might not be an input element, so might not contain a value field. 它可能不是input元素,所以可能不包含value字段。

Try typing JSON.stringify(document.getElementById("path")) into the console to inspect the object. 尝试在控制台中键入JSON.stringify(document.getElementById("path"))来检查对象。

Also try document.getElementById("path").outerHTML to see the attributes and children. 还可以尝试document.getElementById("path").outerHTML查看属性和子级。

Or just document.getElementById("path") and open the tree to view the internals. 或者只是document.getElementById("path")并打开树以查看内部结构。

Make you sure you have an input in DOM with id="path" attribute value. 确保您在DOM中input属性值为id="path"

For example - <input id="path"> 例如- <input id="path">

If that is not present in the DOM then getElementById will always return null. 如果DOM中不存在该值,则getElementById将始终返回null。

You can open Chrome-Dev Tool and search this #path in Elements tab. 您可以打开Chrome-Dev工具并在“元素”标签中搜索此#path That should highlight that input, if it is not then you are targeting wrong element. 那应该突出显示该输入,如果不是,则您定位的是错误的元素。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM