JavaScript复习

1.改变 HTML 内容
document.getElementById(id)。innerHTML="Hello !";

2.改变 HTML 属性
document.getElementById(id).attribute=new value

3.改变 HTML 样式
document.getElementById(id).style.color="blue";
document.getElementById('p1').style.visibility='hidden'或者visible

4.对事件做出反应
οnclick="this.innerHTML='谢谢!'"

5.使用 HTML DOM 来分配事件
document.getElementById("myBtn").οnclick=function(){displayDate()};

6.onload 和 onunload 事件

onload 和 onunload 事件会在用户进入或离开页面时被触发。

onload 事件可用于检测访问者的浏览器类型和浏览器版本,并基于这些信息来加载网页的正确版本。

onload 和 onunload 事件可用于处理 cookie。

7.创建新的 HTML 元素
取值:document.form.elements[""].value="";
var para=document.createElement("p");
var node=document.createTextNode("这是新段落。");
para.appendChild(node);

8.删除已有的 HTML 元素
var parent=document.getElementById("div1");
var child=document.getElementById("p1");
parent.removeChild(child);
或者
var child=document.getElementById("p1");
child.parentNode.removeChild(child);

9.访问对象的属性
objectName.propertyName

10.访问对象的方法
objectName.methodName()
例子:var message="Hello world!";
      var x=message.toUpperCase();

11.JavaScript for...in 循环
var person={fname:"Bill",lname:"Gates",age:56};
for (x in person)
  {
  txt=txt + person[x];
  }

12。数字属性和方法
属性:
    MAX VALUE
    MIN VALUE
    NEGATIVE INFINITIVE
    POSITIVE INFINITIVE
    NaN
    prototype
    constructor
方法:

    toExponential()
    toFixed()
    toPrecision()
    toString()
    valueOf()

13.String indexOf() 定位字符串中某一个指定字符首次出现的位置
          match()  查找字符串中特定字符,如果找到,返回该字符
      replace  用法str.replace(/Microsoft/,"W3School");用W3School替换Microsoft

14.setTimeout('startTime()',3000) 定时执行startTime()方法

15.var arr = new Array(3); 创建数组
    arr[0] = "George"
    arr[1] = "John"
    arr[2] = "Thomas"
16.join  将字符串或数字连接起来
    arr.join(".") George,John,Thomas

17.sort() 对文字或数字数组进行排序。按字母或数字方式

18.Math.round() 对小数进行四舍五入
19.Math.random() 返回0到1之间的随机数
20.Math.max(),min() 返回两个给定的数中较大或者较小的数字


21.算数值

JavaScript 提供 8 种可被 Math 对象访问的算数值:

    常数
    圆周率
    2 的平方根
    1/2 的平方根
    2 的自然对数
    10 的自然对数
    以 2 为底的 e 的对数
    以 10 为底的 e 的对数

这是在 Javascript 中使用这些值的方法:(与上面的算数值一一对应)

    Math.E
    Math.PI
    Math.SQRT2
    Math.SQRT1_2
    Math.LN2
    Math.LN10
    Math.LOG2E
    Math.LOG10E

22.RegExp 对象用于规定在文本中检索的内容。
定义 RegExp var patt1=new RegExp("e");
RegExp 对象的方法 test()、exec() 以及 compile()。
test() 方法检索字符串中的指定值。返回值是 true 或 false
exec() 方法检索字符串中的指定值。返回值是被找到的值
compile() 方法用于改变 RegExp。
compile() 既可以改变检索模式,也可以添加或删除第二个参数
例子:
var patt1=new RegExp("e");
document.write(patt1.test("The best things in life are free"));
patt1.compile("d");
document.write(patt1.test("The best things in life are free"));

23。Window 尺寸
对于Internet Explorer、Chrome、Firefox、Opera 以及 Safari:

    window.innerHeight - 浏览器窗口的内部高度
    window.innerWidth - 浏览器窗口的内部宽度

对于 Internet Explorer 8、7、6、5:

    document.documentElement.clientHeight
    document.documentElement.clientWidth

或者

    document.body.clientHeight
    document.body.clientWidth

24. window.open() - 打开新窗口
    window.close() - 关闭当前窗口
    window.moveTo() - 移动当前窗口
    window.resizeTo() - 调整当前窗口的尺寸

25.Window Screen
    screen.availWidth - 可用的屏幕宽度
    screen.availHeight - 可用的屏幕高度
26.Window Location
    location.hostname 返回 web 主机的域名
    location.pathname 返回当前页面的路径和文件名
    location.port 返回 web 主机的端口 (80 或 443)
    location.protocol 返回所使用的 web 协议(http:// 或 https://)
    location.href 属性返回当前页面的 URL
    location.assign() 方法加载新的文档。
27.Window History
    history.back() - 与在浏览器点击后退按钮相同
    history.forward() - 与在浏览器中点击按钮向前相同
28.Window Navigator

 navigator.appCodeName  Mozilla
 navigator.appName      Netscape
 navigator.appVersion   5.0 (Windows)
 navigator.cookieEnabled true
 navigator.platform     Win32
 navigator.userAgent    Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0
 navigator.systemLanguage undefined

29.alert("再次向您问好!在这里,我们向您演示" + '\n' +
"如何向警告框添加折行。")
}
30.confirm("确认删除");
   prompt("提示框")

31.setTimeout()和clearTimeout();

在浏览器的状态栏放入一条消息?
window.status = "put your message here"
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值