首页 > 代码库 > 【JavaScript】笔记01——Making Stuff Happen???
【JavaScript】笔记01——Making Stuff Happen???
While, generally speaking, HTML is for content and CSS is for presentation, JavaScript is for interactivity.
1、从HTML到JavaScript,像下面这样:
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <script> alert("Hello, world."); </script> </body></html>
alert的意思是警告,类似于message. 效果上就是弹出一个对话框。
2、引用外部的.js文件
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <script src="http://www.mamicode.com/script.js"></script> </body></html>
script.js
alert("Hello, world.");
3、在浏览器Console中运行JavaScript代码,Chrome进入Console的快捷键是F12
4、在正式开始学习前,需要强调的是:
A browser then runs JavaScript line-by-line, starting at the top of the file or script
element and finishing at the bottom (unless you tell it to go elsewhere).
5、询问用户姓氏的小程序
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <script type="text/javascript"> var surname = prompt(‘Greetings friend, may I enquire as to your surname?‘); </script> </body></html>
通过浏览器运行这段代码,将跳出一个“小盒子”,询问你的姓氏。
6、变量类似于一个“盒子”,我们利用它来储存数据;它具有“名”和“值”。
声明(Declaration)
var surname;var age;
初始化(Initialization)
var name = "Tom";
赋值(assignment)
name = "Andy";age = 43;
【JavaScript】笔记01——Making Stuff Happen???
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。