本文实例讲述了js console.log打印对像与数组用法。分享给大家供大家参考,具体如下:
console.log是什么东西,其实就是一个打印js数组和对像的函数而已,就像是php的print_r,var_dump。console.log这个函数本身没什么好说的,这篇博客告诉大家怎么去用这个函数。在说这个函数之前,我想大家用的最多查看js输出,是alert吧,但是alert,只能弹string或者是int的
一、测试文件test.html
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>console.log test</title><script type="text/javascript">
var testobj =
{
'id': 1,
'content': 'test',
'firstname': function() {
document.getElementById('firstname').value = "zhang";
},
'lastname': function() {
document.getElementById('lastname').value = "ying";
}
};
<!-- 打印对像 -->
console.log(testobj);
</script><input type="text" id="firstname" name="firstname" value=""><input type="text" id="lastname" name="lastname" value=""><p><strong>二、chrome 开发工具查看js对像</strong></p>
<p>@@##@@</p><div class="aritcle_card flexRow artxards">
<div class="artcardd flexRow">
<a class="aritcle_card_img" rel="nofollow" href="/xiazai/skill13666" title="从网页中提取schema.org、Open Graph和JSON-LD元数据以用于索引"><img
src="https://img.php.cn/upload/skill/001/246/273/6adaf20d3191a227.jpg" alt="从网页中提取schema.org、Open Graph和JSON-LD元数据以用于索引" onerror="this.onerror='';this.src='/static/lhimages/moren/morentu.png'" ></a>
<div class="aritcle_card_info flexColumn">
<a rel="nofollow" href="/xiazai/skill13666" title="从网页中提取schema.org、Open Graph和JSON-LD元数据以用于索引" class="overflowclass">从网页中提取schema.org、Open Graph和JSON-LD元数据以用于索引</a>
<p class="overflowclass">使用 extruct 从原始 HTML 中提取机器可读的元数据,以便代理可以在不依赖脆弱的全页解析的情况下对页面进行分类、去重或丰富。它最适合元数据采集工作流,而不适用于爬取整个网站或渲染 JavaScript 密集型页面。</p>
</div>
<a rel="nofollow" href="/xiazai/skill13666" title="从网页中提取schema.org、Open Graph和JSON-LD元数据以用于索引" class="aritcle_card_btn flexRow flexcenter"><b></b><span>下载</span>
</a>
</div>
</div>
<p>console chrome</p>
<p>现在chrome开发者工具和firebug,我用的时候,一半对一半。chrome开发者工具,还有一个功能,firebug不具有.</p>
<p>控制台可以运行js,如果这个页面是iframe的话,firebug只能运行在父级上面,而chrome可以选择里面的页面执行,如果下图</p>
<p>@@##@@</p>
<p>chrome iframe console</p>
<p><strong>三、firebug查看js对像</strong></p>
<p>@@##@@</p>
<p>firebug console</p>
<p>更多关于JavaScript数组相关内容感兴趣的读者可查看本站专题:《<a target="_blank" href="http://www.jb51.net/Special/278.htm">JavaScript数组操作技巧总结</a>》</p>
<p>希望本文所述对大家JavaScript程序设计有所帮助。</p>



Java免费学习笔记:立即使用
解锁 Java 大师之旅:从入门到精通的终极指南










