W3School JS Quiz

来源:互联网 发布:微信支付网页授权域名 编辑:程序博客网 时间:2024/06/06 16:56

18/20

需复习巩固的知识点:

JavaScript Maths

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

Syntax

var x = Math.PI; // Returns PIvar 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 radiansatan(x) 反正切Returns the arctangent of x as a numeric value between -PI/2 and PI/2 radiansatan2(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 integercos(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 integerlog(x)Returns the natural logarithm (base E) of xmax(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 integersin(x)Returns the sine of x (x is in radians)sqrt(x) 平方根Returns the square root of xtan(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