W3School JS Quiz

18/20

需复习巩固的知识点:

JavaScript Maths

 Math object allow you to perform mathematical tasks on numbers 对数字进行数学运算操作

Syntax

var x = Math.PI; // Returns PI
var y = Math.sqrt(16); // Returns the square root of 16


Math Object Properties

JavaScript provides eight mathematical constants JS提供 8个数学常量

Math.E自然对数函数的底数,又称欧拉数 (approx. 2.718)
Math.PI  (approx. 3.14)


Math.SQRT2 square root of 2 (2的平方根 approx. 1.414)
Math.SQRT1_2 square root of 1/2 (approx. 0.707)


Math.LN2 natural log of 2 (以e为底2的对数 approx. 0.693)
Math.LN10 (approx. 2.302)


Math.LOG2E base-2 log of E (以2为底E的对数 approx. 1.442)
Math.LOG10E (approx. 0.434)

Math Object Methods

abs(x) 绝对值 Returns the absolute value of x  
acos(x) 反余弦 Returns the arccosine of x, in radians 用弧度表示
asin(x) 反正弦 Returns the arcsine of x, in radians
atan(x) 反正切 Returns the arctangent of x as a numeric value between -PI/2 and PI/2 radians
atan2(y,x) Returns the arctangent of the quotient of its arguments 返回从 x 轴到点 (x,y) 的角度 -PI/2 与 PI/2 弧度之间)
ceil(x) 向上舍入 Returns x, rounded upwards to the nearest integer
cos(x) Returns the cosine of x (x is in radians)
exp(x) Returns the value of Ex  以e为底
floor(x) 向下舍入 Returns x, rounded downwards to the nearest integer
log(x) Returns the natural logarithm (base E) of x
max(x,y,z,...,n) Returns the number with the highest value 求最大值
min(x,y,z,...,n) Returns the number with the lowest value 求最小值
pow(x,y) Returns the value of x to the power of y 返回x的y次幂
random() Returns a random number between 0 and 1 产生(0,1)之间的随机数
round(x) 四舍五入 Rounds x to the nearest integer
sin(x) Returns the sine of x (x is in radians)
sqrt(x) 平方根 Returns the square root of x
tan(x) Returns the tangent of an angle


JavaScript Window

The Browser Object Model (BOM) allows JavaScript to "talk to" the browser.

The window object is supported by all browsers. 所有浏览器都支持窗口对象

All global JavaScript objects, functions, and variables automatically become members of the window object.

所有JS全局变量、对象、函数都自动成为window对象的成员属性或方法。

Even the document object (of the HTML DOM) is a property of the window object


Window Size

Three different properties can be used to determine the size of the browser window (the browser viewport, NOT including toolbars and scrollbars). 

三种不同的属性可以用来确定浏览器窗口的尺寸,不包含工具条和滚动条。

A practical JavaScript solution (covering all browsers):

var w=window.innerWidth
|| document.documentElement.clientWidth
|| document.body.clientWidth;

var h=window.innerHeight
|| document.documentElement.clientHeight
|| document.body.clientHeight;
第一种针对Internet Explorer, Chrome, Firefox, Opera, and Safari, 后两者针对 Internet Explorer 8, 7, 6, 5

Other Window Methods

  • window.open() - open a new window 打开新窗口
  • window.close() - close the current window 关闭当前窗口
  • window.moveTo() - move the current window 移动到当前窗口
  • window.resizeTo() - resize the current window 重定义当前窗口尺寸


JavaScript Window Navigator

The window.navigator object contains information about the visitor's browser, 该对象包含了用户浏览器的信息,可以不写window前缀
txt = "<p>Browser CodeName: " + navigator.appCodeName + "</p>";
txt+= "<p>Browser Name: " + navigator.appName + "</p>";
txt+= "<p>Browser Version: " + navigator.appVersion + "</p>";
txt+= "<p>Cookies Enabled: " + navigator.cookieEnabled + "</p>";
txt+= "<p>Platform: " + navigator.platform + "</p>";
txt+= "<p>User-agent header: " + navigator.userAgent + "</p>";
txt+= "<p>User-agent language: " + navigator.systemLanguage + "</p>";

Warning !!!

The information from the navigator object can often be misleading, and should not be used to detect browser versions because:

导航器对象获得的信息经常是有误导的,最好不要用来检测浏览器版本信息,因为:

  • The navigator data can be changed by the browser owner 导航器数据可以被浏览器owner改变
  • Some browsers misidentify themselves to bypass site tests 一些浏览器伪装自己以通过网站检测
  • Browsers cannot report new operating systems, released later than the browser 浏览器不能报告那些发行比它晚的新的操作系统


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值