js 知识总结

来源:互联网 发布:村淘和淘宝有什么区别 编辑:程序博客网 时间:2024/06/08 03:57
JS 总结

事件

1 语法: onclick = js ("函数")("语句")
2 事件句柄: onclick onfcus ...
3 鼠标/键盘属性: altKey (event.altKey==1 表示alt 这个建被按)event.clientX(鼠标横坐标)

DOM 处理


1 访问节点
getElementById()  getElementsByTagName()  getElementsByClassName("");

2 操作html
改变html内容:document.getElementById(id).innerHtml = new Html
改变html属性:(获取节点).attribute = new value
(document.getElementById("image").src = "a.jpg":)

3 操作css
改变css样式:(获取节点).style.property = new style
document.getElementById("p2").style.color = "bule";
显示影藏:(获取节点).visibility = 'hidden' (visible)

4 操作节点
增加节点 步骤
1 创建<p>
  var para = doucument.createElemnt("p");
2 创建节点内容
  var node = doucument.createTextNode("内容");
3 将内容追加到节点
  para.appendChild(node);
4 将新元素放入指定的位置
  var elemnet = document.getElementById("div1");
  element.appenChild(para);

删除节点
var parent = document.getElementById("div1");
var child = document.getElemntById("p1");
parent.removeChild(child);

Window(BOM流浪器对象模型)

1 window :window.innerHeight(Width)浏览器的高和宽
2 screen:screen.availWidth(Height) 可用屏幕宽高
3 Location: window.location("src") 刷新
4 History: window.history.back()  (forward) 无刷新
5 PopuAlert: alert("警告框"); confirm("确定框") ; prompt("提示框")
原创粉丝点击