美文网首页
43.JavaScript

43.JavaScript

作者: 为梦想战斗 | 来源:发表于2018-11-12 20:02 被阅读0次

一、基础
向文档中输出文本:<script>document.write("Hello Javascript");</script>。script标签可以放在html的任何地方,一般建议放在head标签里。如果有多段script代码,会按照从上到下,顺序执行。外部:<html><script src="d/hello.js"></script></html>

变量:var x = 1;

调试办法:alert、浏览器

基本数据类型:undefined、Boolean、Number、String、var、typeof、null

类型转换:伪对象概念:javascript是一门很有意思的语言,即便是基本类型,也是伪对象,所以他们都有属性和方法。无论是Number,Boolean还是String都有一个toString方法,用于转换为字符串。parseInt()和parseFloat(),可以转换为数字。使用内置函数Boolean() 转换为Boolean值。

函数:function print(){document.write("这一句话是由一个自定义函数打印");}print();

事件:javascript允许html与用户交互的行为。 用户任何对网页的操作,都会产生一个事件。事件有很多种,比如鼠标移动,鼠标点击,键盘点击等等。

算数运算符:+-*/

逻辑运算符:==、!=、>、>=、<、<=、===、!==、?:

条件语句:if-else、switch

循环语句: for, while, do-while, for-each

错误处理:try catch

对象:Number(new Number、MIN_VALUE、MAX_VALUE、Nan、toFixed、toExponential、valueOf)、String(new String()、length、charAtcharCodeAt、concat、indexOf lastIndexOf、localeCompare、substring、split、replace、charAt、concat、substring)、Date(new Date、getFullYear、getMonth、getDate、getHours、getMinutes、getSeconds、getMilliseconds、getDay、getTime、setFullYear、setMonth、setDate、setHours、setMinutes、setSeconds)、Array(new Array、length、for、for in、concat、join、push pop、unshift shift、sort)、Math(E PI、abs、min、max、pow、round、random)。自定义对象:通过function设计,通过prototype实现增加新方法。

二、BOM
BOM:浏览器对象模型(Browser Object Model)。包括Window、Navigator、Screen、History、Location

Window:innerWidth、innerHeight、outerWidth、outerHeight、open

Navigator:appName、appVersion、appCodeName、platform、cookieEnabled、userAgent

Screen:width、availwidth

History:back、go(-2)

Location:reload、assign("/")、protocol、hostname、port、host、pathname、hash、search

弹出框:alert、confirm、prompt

计时器:setTimeout、setInterval、clearInterval、document.write()

相关文章

  • 43.JavaScript

    一、基础向文档中输出文本: document.write("Hello Javascript"); 。script...

网友评论

      本文标题:43.JavaScript

      本文链接:https://www.haomeiwen.com/subject/friheftx.html