轉自:http://onlylovexue.javaeye.com/blog/267511
用href=# 和 javascript:void(0) 可以使鏈接后什么操作都不執行javascript:void(alert('ok'))
div.style.visibility="hidden"(層掩藏)|"visible"(層顯示)
div.style.display=""(還原空間)|"none"(抽取空間)
document.body.scrollLeft:指窗口向左滾動的距離 document.body.scrollTop離最上的距離
posTop的數值其實和top是一樣的,但區別在于,top固定了元素單位為px,而posTop只是一個數值,因此一般使用posTop來進行運算
div.style.posLeft:是包括窗口滾動的那部分 并且是數字的 而left是有px 的
event.x:是指觸發的事件上 相對與現在窗口的距離
event.offsetX:事件觸發時相對于事件對象的X值
div.style.zIndex 與style="z-Index:100" 的表達方式
-----------------------------------------------------
用js 的createElement("div") 中的div不是隨意的 而是對應html中的一個標記名
createElement("option") 用來創建選項節點
var select=document.createElement("select");
var cells=select.options;
var op=new Option("value","值");
cells.add(op);
或者用document.createElement("select").appendChild(document.createElement("option"))
------------------------------------------------------
opener:指用WINDOW.OPEN等方式創建的新窗口對應的原窗口。
window.parent是相對于iframe而言的父頁面,window.opener是window.open打開子頁面的父頁面
獲取父窗體的document的引用:window.opener.document
引用demo:
var _parentWin = window.opener;
_parentWin.form1.username.value = "xxxx" ;
并且可以通過_parentWin 獲取對document對象的引用
-----------------------------------------------------
Window 對象是 JavaScript 層級中的頂層對象。Window 對象代表一個瀏覽器窗口或一個框架。Window 對象會在 <body> 或 <frameset> 每次出現時被自動創建
-----------------------------------------------------
DOM屬性:
childNodes 該屬性返回一個數組,這個數組由給定元素節點的子節點構成 可用childNodes[i]來進行訪問 與table 的rows一樣 和select 的options一樣
firstChild 返回第一個子節點
lastChild 返回最后一個子節點
nextSibling 返回給定節點的下一個子節點
parentNode 返回一個給定節點的父節點
previousSibling 返回給定節點的下一個子節點??
rowIndex 對于row可以獲取其row所在的table 的位置
cellIndex 對于cell可以獲取其cell所在的row的位置
1 createElement(element)
創建一個指定標簽名創建一個新的元素節點,返回值為指向新建元素節點的引用指針。
eg) var para = document.createElement("p");
document.body.appendChild(para);
2 createTextNode()
創建一個包含著給定文本的新文本節點,返回一個指向新建文本節點的引用指針:
reference = document.createTextNode()
參數為新建文本節點所包含的文本字符串
var message = document.createTextNode("hello world");
var container = document.createElement("p");
container.appendChild(message);
document.body.appendChild(container);
3 cloneNode()
reference = node.cloneNode(deep)
為給定節點創建一個副本,參數為 true 或者 false,true 表示同時復制該節點的子節點,false 則不復制任何子節點。
var para = document.createElement("p");
var message = document.createTextNode("hello world");
para.appendChild(message);
document.body.appendChild(para);
var newpara = para.cloneNode(true);
document.body.appendChild(newpara);
4 appendChild()
reference = node.appendChild(newChild);
插入節點,例子參考前面。
5 insertBefore()
reference = element.insertBefore(newNode,targetNode)
將一個給定節點插入到一個給定元素節點的給定子節點的前面,返回一個指向新增子節點的引用指針。
var container = document.getElementById("content");
var message = document.getElementById("fineprint");
var para = document.createElement("p");
container.insertBefore(para,message);
6 removeChild()
reference = element.removeChild(node)
將從一個給定元素利刪除一個子節點,返回一個指向已被刪除的子節點的引用指針。
當某個節點被 removeChild()刪除后,此節點所有子節點都被刪除。
7 replaceChild()
reference = element.replaceChild(newChild,oldChild)
把一個給定父元素里的一個子節點替換為另外一個節點,oldChild 節點必須是 element 元素的一個子節點,返回值是一個指向已被替換的那個子節點的引用指針。
var container = document.getElementById("content");
var message = document.getElementById("fineprint");
var para = document.createElement("p");
container.replaceChild(para,message);
8 setAttribute()
element.setAttribute(attributeName,attributeValue);
為給定元素節點添加一個新的屬性值或是改變它的現有屬性
9 getAttribute
attributeValue = element.getAttribute(attributeName)
返回一個給定元素的一個給定屬性節點的值。
10 getElementById()
element = document.getElementById(ID)
尋找一個有著給定 id 屬性值的元素,返回一個元素節點
11 getElementByTagName()
用于尋找有著給定標簽名的所有元素:
elements = document.getElementsByTagName(tagName)
返回一個節點集合。
12 hasChildNodes
用來檢查一個給定元素是否有子節點
booleanValue = element.hasChildNodes
返回 true 或 false。
------------------------------------------------------
對于select 標簽的option:
new Option(text,value);聲明一個新的optioin對象,參數text 是指純文本內容
var cells=select.options:獲取一個select子項的集合 返回是一個數組類型
添加方式:select.options.add(oop); 或cells.add(oop);
刪除方式:select.options.remove(i);或cells.remove(i);
-----------------------------------------------------
yyyy:年份
MM:月
dd:日
mm :分鐘
hh:12小時制度 區別于oracle中的
HH:24小時制度
ss:秒
------------------------------------------------------
你看這個結果:
alert("Hello world" + null); // output "Hello worldnull"
在 java 中 : System.out.println("Hello world" + null); // output "Hello worldnull"