打印对象和数组的用法
本文描述了js console.log打印对象和数组的用法。分享给大家参考,如下:
什么是console.log,其实只是一个打印js数组和对象的函数,就像php的print_r,var_dump一样。函数console.log本身没什么好说的。这个博客告诉大家如何使用这个功能。在讲这个函数之前,我觉得最多可以用js输出,就是alert,但是alert只能玩string或者int。
测试文件的test.html。
html xmlns=' http://www . w3 . org/1999/XHTML ' hearteta http-equiv=' Content-Type ' Content=' text/html;charset=utf-8 '/title console . log test/title/head script type=' text/JavaScript ' var testobj={ ' id ' : 1,' content': 'test ',' first name ' : function(){ document . getelementbyid(' first name ')。值='张';},last name ' : function(){ document . getelementbyid(' last name ')。值=' ying} };-打印图像-console . log(testobj);/script body input type=' text ' id=' first name ' name=' first name ' value=' input type=' text ' id=' last name ' name=' last name ' value=' '/body/html ii。查看js对象的chrome开发工具。
控制台镀铬
现在chrome开发者工具和firebug,当我使用它们的时候,是一半对一半。Chrome开发者工具,还有另外一个firebug没有的功能。
控制台可以运行js。如果这个页面是iframe,firebug只能在父页面上运行,而chrome可以选择里面的页面执行,如下图所示。
chrome iframe控制台
第三,firebug视图js对象。
firebug控制台
更多对JavaScript数组感兴趣的读者,请查看本网站主题:《JavaScript数组操作技巧总结》。
希望本文对JavaScript编程有所帮助。
版权声明:打印对象和数组的用法是由宝哥软件园云端程序自动收集整理而来。如果本文侵犯了你的权益,请联系本站底部QQ或者邮箱删除。