1. 程式人生 > >JS中幾類事件及其相關的函數

JS中幾類事件及其相關的函數

code 提交表單 取整 滾動 submit shift div name height

<script>
        //鼠標事件
        //鼠標事件對象:e或event
        //獲取事件對象的位置document.getdocumnetsByTagNamem
        //獲取整個窗口的寬度(距左)和高度(包括滾動條):window.innerHeight、window.innerWidth
        //獲取整個窗口的寬度(距左)和高度(不包括滾動條):document.body.clientWidth
        //鼠標相對於整個窗口的寬度(距左)和高度:ev.clientX、ev.clientY
        //鼠標距離元素的寬度(距左)和高度:oDiv.offsetLeft、oDiv.offsetTop
//鼠標按下事件:onmousedown //鼠標擡起事件:onmouseup //鼠標移動事件:onmousemove //重新設置屬性:oDiv.style.屬性 //鍵盤事件:onkeydown //通過e或者event定義的鍵盤事件對象:ev //ev.keyCode:獲取輸入鍵的ASCII碼值 //對於一些特殊的鍵需要特別設置進行判斷:alt->altKey、ctrl->ctrlKey、shift->shiftKey //
表單提交事件:onsubmit //用法:onsubmit="return func();" function func(){return true} //可以用<button></button>reg.onclick = function () {手動提交表單form.submit()} //窗口尺寸隨著用戶鼠標更改而顯示現在尺寸事件:onresize //更改後的尺寸:document.documentElement.clientWidth(/Height) //窗口滾動事件:onscroll
//滾動窗滾動的距離:document.documentElement.scrollWidth(/Height) //document.write(自定義內容):在網頁頁面顯示一段內容 //document.title=變量:在標題頭顯示內容 </script>

JS中幾類事件及其相關的函數