1. 程式人生 > >11.7-2017復習總結雜

11.7-2017復習總結雜

內容 ctr 不同 print 剪切 som text ext att

1
img=document.createElement("img");
就相當於html中的<img> 創建了這樣一個對象


舉個例子:

如果是相對整個窗口的坐標的話可以這樣寫
var x = "100px", y = "100px";
var img = document.createElement( "img" );
document.body.appendChild( img );
image.style.position = "absolute";
image.style.left = x;
image.style.top = y;
這個圖片就會顯示在窗口左上角坐標(100,100)處


總結:document.createElement("標簽元素");-----創建新的標簽元素;
document.createAttribute("元素name")----創建新的屬性;
document.createComment("註釋 ");---------創建新的comment(註釋);
document.createTextNode(""); -------------創建新的文本;
創建文本 eg:
function myFunction(){
var h=document.createElement("H1");
var t=document.createTextNode("Hello World");
h.appendChild(t);
document.body.appendChild(h);
};
2


----HTML 中:
<element onmouseup="SomeJavaScriptCode">
----JavaScript 中:
object.onmouseup=function(){SomeJavaScriptCode};

鼠標事件 -DOM-event


提示: 與 onmouseup 事件相關聯的事件觸發次序 (左邊/中間 鼠標按鈕):
onmousedown
onmouseup
onclick
與 onmouseup 事件相關聯的事件觸發次序 (右邊鼠標按鈕):
onmousedown
onmouseup
oncontextmenu

監聽事件
eg:addEventListener屬性
<script>
document.getElementById("fname").addEventListener("focus", myFunction);
function myFunction() {
document.getElementById("fname").style.backgroundColor = "red";
}
</script>
表單事件:
onfocusin 事件在一個元素即將獲得焦點時觸發。
提示: onfocusin 事件類似於 onfocus 事件。 主要的區別是 onfocus 事件不支持冒泡。
因此,如果你想知道元素或者其子元素是否獲取焦點,需要使用 onfocusin 事件。
onfocusout

oninput 事件在用戶輸入時觸發。
該事件在 <input> 或 <textarea> 元素的值發生改變時觸發。
提示: 該事件類似於 onchange 事件。不同之處在於 oninput 事件在元素值發生變化是立即觸發, onchange 在元素失去焦點時觸發。
另外一點不同是 onchange 事件也可以作用於 <keygen> 和 <select> 元素。

onsearch 事件在用戶按下"ENTER(回車)" 按鍵或點擊 type="search" 的 <input> 元素的 "x(搜索)" 按鈕時觸發。


剪貼板事件:


屬性 描述
oncopy 該事件在用戶拷貝元素內容時觸發
oncut 該事件在用戶剪切元素內容時觸發
onpaste 該事件在用戶粘貼元素內容時觸發


---------發現了小問題當內容沒有被選中,也是以發生以上事件


打印事件

onafterprintprint///onbeforeprint


提示: 快捷鍵,如 Ctrl+P 可以設置頁面打印。


拖動事件(HTML5Z中的常見屬性)


3
提示:Document 對象是 Window 對象的一部分,可通過 window.document 屬性對其進行訪問。

document.addEventListener() 方法用於向文檔添加事件句柄。
提示: 可以使用 document.removeEventListener() 方法來移除 addEventListener() 方法添加的事件句柄。
提示:使用 element.addEventListener() 方法為指定元素添加事件句柄。

4
preventDefault() 方法阻止元素發生默認的行為(例如,當點擊提交按鈕時阻止對表單的提交)。
$("a").click(function(event){
event.preventDefault();
});

11.7-2017復習總結雜