[英]In Plain/Pure Javascript, how do you find out what available methods or properties an element object has?
Using only pure javascript without jquery, how do you display all the possible methods and properties of an element object? 仅使用没有jquery的纯javascript,如何显示元素对象的所有可能方法和属性? Say I have the body object - document.getElementByTagName('body')[0] 假设我有身体对象 - document.getElementByTagName('body')[0]
How do I list out all the possible methods I can use? 如何列出我可以使用的所有可能方法? And what properties it has? 它有什么属性? I know I can use .click() and .setAttribute but what else is there? 我知道我可以使用.click()和.setAttribute但还有什么呢?
How would I find out using the Chrome console? 我如何找到使用Chrome控制台的信息?
Rather than using console.log
, I'd suggest console.dir
而不是使用console.log
,我建议使用console.dir
console.dir(myObj);
dir
will show your Object's properties even if you pass a Node , rather than showing the tree-view in the console, which will happen with log
if it recognises the Object as a Node . 即使您传递了一个节点 , dir
也会显示您的对象的属性,而不是在控制台中显示树视图,如果它将对象识别为节点 ,则会在log
。
Somewhere in your code you want to log the object to the console: 在代码中的某处,您希望将对象记录到控制台:
console.log(MyObjectInstance);
Then when you open chrome developer tools you can go to 'console' and view your object. 然后,当您打开chrome开发人员工具时,您可以转到“控制台”并查看您的对象。 There should be a little arrow next to the logged object that you can click to view all of its methods and attributes. 记录对象旁边应该有一个小箭头,您可以单击该箭头以查看其所有方法和属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.