如何测试javascript代码
网站优化小编十一月 26, 2019 22人已围观
由于JavaScript程序不能像C++、Python程序等单独运行,不利于测试一段代码的功能,那么我们该如何车上JavaScript代码呢?下面我们就通过一个小例子来看一下如何测试JavaScript代码。
简单测试一小段JavaScript代码:
步骤
(1)新建一个test.html文件
(2)在test.html文件中书写以下内容
<!doctype html> <html> <head> <meta charset="utf-8"> <title>test</title> <script type="text/javascript"> </script> </head> <body> </body> </html>
(3)在test.html中编写需要测试的JS代码,如下
<!doctype html> <html> <head> <meta charset="utf-8"> <title>test</title> <script type="text/javascript"> function Student(name, age){ this.name = name; this.age = age; this.description = function(){ return this.name + "的年龄是:" + this.age; } } var p4 = new Student("Tony", 28); var p5 = new Student("Tom", 40); console.log(p4.description()) //输出为:Tony的年龄是:28 console.log(p5.description()) //输出为:Tom的年龄是:40 </script> </head> <body> </body> </html>
(4)再用浏览器打开test.html,按F12,查看console.log()打印输出的内容
总结:
JavaScript代码测试:需要将JavaScript代码嵌入HTML网页中,然后通过浏览器打开HTML文件,按F12快捷键进入浏览器的控制台查看JavaScript输出效果。
下一篇: 一米地推裂变系统有哪几种模式
上一篇: SEM搜索引擎营销是什么实现实现推广效果
相关文章
文章评论
点击排行

本栏推荐
标签云
站点信息
- 站点运行:227天
- 网站程序:Wordpress
- 主题模板:bvseo
- 文章统计:3199 条
- 文章评论:21 条
- 微信公众号:扫描二维码,关注我们

发表评论