简体   繁体   English

在Plain / Pure Javascript中,如何找出元素对象有哪些可用的方法或属性?

[英]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.

相关问题 你怎么知道HTML元素是否有一个普通的Javascript类? - How do you find out if an HTML element has a certain class with plain Javascript? 如何仅使用lodash或纯JavaScript添加新对象或更新现有对象属性? - How do you add new or update existing object properties using lodash only or plain javascript? 如何找到所有Javascript对象的方法和属性? - How to find all Javascript object methods and properties? 如何在JavaScript中找出调用者对象 - How do you find out the caller Object in JavaScript 如何在 javascript 中的纯 function 中更新 object? - How do you update an object in a pure function in javascript? 如何在javascript中更新对象的属性? - How do you update the properties of an object in javascript? 如何找出Javascript正在调整大小的元素 - How to find out what Javascript is resizing element 如何使用普通的纯Javascript检测Nav是否有子元素? - How to detect if Nav has child element using plain Plain Javascript? 当您收到消息“对象不支持此属性或方法”时,您如何找到“对象”是什么? - When you get the message “Object doesn't support this property or method”, how do you find out what “Object” is? 如何在 Javascript 中检查 object 和此 object 可用的方法 - how to check the object and methods available for this object in Javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM