javascriptjavascript
document.write(‘my name is liguoxiang ‘);java
经过ID获取node
var x = document.getElementById(“lgx”);app
经过标签获取函数
var y = getElementsByTagName("p");spa
经过类名获取对象
var y = getElementsByClass("class");seo
document.getElementById(id).innerHTML=new HTML事件
document.getElementById(id).attribute=new valueip
如:
document.getElementById("image").src="landscape.jpg";
document.getElementById(id).style.property=new style
如:
document.getElementById("p2").style.color="blue";
Ø onkeyup
Ø onclick 当用户点击鼠标时
onload 和 onunload 事件会在用户进入或离开页面时被触发
如:
<body onload="checkCookies()">
Ø onmouseover 和 onmouseout 事件可用于在用户的鼠标移至 HTML 元素上方或移出元素时触发函数。
Ø onmousedown, onmouseup 以及 onclick 构成了鼠标点击事件的全部部分。首先当点击鼠标按钮时,会触发 onmousedown 事件,当释放鼠标按钮时,会触发 onmouseup 事件,最后,当完成鼠标点击时,会触发 onclick 事件
var para=document.createElement("p"); //建立新的 <p> 元素:
var node=document.createTextNode("这是新段落。");//建立文本节点
para.appendChild(node); //向 <p> 元素追加这个文本节点
var element=document.getElementById("div1"); element.appendChild(para);
var parent=document.getElementById("div1"); var child=document.getElementById("p1"); parent.removeChild(child); //从父元素中删除子元素:
或
var child=document.getElementById("p1"); child.parentNode.removeChild(child); //找到父节点再删除子节点
var txt="Hello world!"document.write(txt.length)
var txt="Hello world!"document.write(txt.toUpperCase())
var str="Visit Microsoft!"
document.write(str.replace(/Microsoft/,"W3School"))