HTML
HTML <>button> 表單按鈕 <>button>按鈕文字<>/button> 按鈕文字 <>input type="button" value="按鈕文字" > button : 屬性 disabled : 不能夠動作的按鈕,僅能看不能按。 name : 按鈕的名稱 type : button(單純按鈕)、reset(清空表單)、submit(送出表單) value : 按鈕文字、 按鈕的値 onclick="function ()" onclick="{javascript}" <>input onclick="alert('按我')" type="button" value="按我" /> <>button onclick="alert('按我')" > 按我 <>/button> 按我 <>button onclick="alert('按我')"><>img src="url" /><>/button> <>button style="background:url(圖片網址)" />
Target.addEventListener( ) 監聽物件 Target.addEventListener(event,function,Capture) Target : 監聽物件,表示觸發事件的元素 Document、Window、id..... event : mousedown、mouseenter、mouseleave、mousemove、 監聽事件 mouseout、mouseover、mouseup、mousewheel 、 click、dblclick keydown、keypress、keyup blur、focus、abort、beforeinput、 compositionstart、compositionupdate、compositionend、 error、focusin、focusout、input、load、resize、 scroll、select、unload、wheel Target.removeEventListener() 刪除監聽 removeEventListener()方法用於刪除與addEventListener(), 方法關聯的事件處理程序。
Target.addEventListener(event ,function(e){} ,false) event. MouseEvent 監聽事件 : mouseenter 移動進入 父元素 的時候會觸發。 mouseleave 移動離開 父元素 的時候會觸發。 mouseover 移動進入到元素上時就會觸發。 mouseout 移動離開到元素上時就會觸發。 mouseup 放開滑鼠按鍵時發生。 mousedown 按一下滑鼠按鍵時發生, 屬性返回, e.detail 0:無按鍵 1:按鍵 e.button 0:左鍵 1:中間鍵 2:加鍵 mousemove 鼠標移動位置, 屬性返回, e.pageX 與文檔左側邊緣的距離(單位像素) e.pageY 與文檔上側邊緣的距離(單位像素) mousewheel 滾輪事件。
<div id="mainID"> click me 1 click me 2 click me 3 click me 4 click me 5 </div>
mainID.addEventListener('click', function(e){ e.target.style.color=rgb ; }) e.target : mainID 內的物件。
addEventListener click move 點擊 移動 事件 window.addEventListener('mouseup', function(e){ Dw=0 }) DIV.addEventListener('mousedown',function(e){ Dw=1 }) window.addEventListener('mousemove', function(e){ if(Dw==1 ) { DIV.style.top =e.pageY-30+"px" ; DIV.style.left=e.pageX-30+"px" ;} })
addEventListener() to class <input class="round" type="text" value="111"> <input class="round" type="text" value="222"> <input class="round" type="text" value="333"> <input class="round" type="text" value="444"> <script> var Class= document.querySelectorAll(".round") ; Class.forEach((round) => { round.addEventListener("mouseover", function() { round.style.backgroundColor = "bisque"; round.focus() ; round.select() ; }) }) Class.forEach((round) => { round.addEventListener("mouseout", function() { round.style.backgroundColor = "ivory"; round.blur() ; }) }) </script>
addEventListener() to Tag <input type="button" value="1"> <input type="button" value="2"> <input type="button" value="3"> <input type="button" value="4"> <div id="dp"></div> <script> var Tag= document.querySelectorAll("input") ; Tag.forEach((round) => { round.addEventListener("click", function() { dp.innerHTML = round.value ; }) }) </script>
<script> function sortMe(x){ var tmpAry = new Array(); for (var i=0; i<5 ;i++) { tmpAry[i] = new Array(); if(x=='text' ){ tmpAry[i][0] = Sel[i].text; tmpAry[i][1] = Sel[i].value; } if(x=='value' ){ tmpAry[i][0] = Sel[i].value; tmpAry[i][1] = Sel[i].text; } } tmpAry = tmpAry.sort() ; for (var ii=0; ii<5 ;ii++) { if(x=='text' ){ Sel[ii].text = tmpAry[ii][0] ; Sel[ii].value = tmpAry[ii][1] ;} if(x=='value'){ Sel[ii].value = tmpAry[ii][0] ; Sel[ii].text = tmpAry[ii][1] ;} } } </script>