搭建自己的base.js(2)-其他事件方法
生活随笔
收集整理的這篇文章主要介紹了
搭建自己的base.js(2)-其他事件方法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
獲取鼠標按鍵
// 獲取鼠標按鍵,getButton:function(event) {//DOM,先檢測是否支持DOM鼠標事件if(document,implementation.hasFeature("MouseEvents","2.0")) {return event.button; //0主鍵,1滾輪,2次鍵} else { //IE8及之前switch(event.button) {case 0:case 1:case 3:case 5:case 7:return 0; //都按下了主鍵,有些結合其他鍵同時按case 2:case 6:return 2; //次鍵case 4:return 1; //滾輪}}},獲取滾輪滾動差
// 獲取鼠標滾輪getWheelDelta:function(event) {if(event.wheelDelta) {return (event.wheelDelta); //120的倍數,滾輪向上滾為正,IE,Chrome} else {//firefox方向相反,且滾一次是3的倍數return -event.detail * 40; }},獲取鍵盤編碼
// 獲取鍵盤編碼getCharCode:function(event) {if(typeof event.charCode == 'number') {return event.charCode; //IE9,Firefox,Chrome} else {return event.keyCode; //IE8}},獲取剪切板文本
// 獲取剪切板文本getClipboardText:function(event) {//IE保存在window中,var clipboardData = (event.clipboardData || window.clipboardData);return clipboardData.getData('text');},設置剪切板內容
// 設置剪切板內容setClipboardText:function(event,value) {if(event.clipboardData) {//Chrome,Safari,設置成功返回true,text/plan為數據類型return event.clipboardData.setData('text/plain',value); } else if (window.clipboardData) {return window.clipboardData.setData('text',value); //IE}}
轉載于:https://www.cnblogs.com/yoomin/p/3950891.html
總結
以上是生活随笔為你收集整理的搭建自己的base.js(2)-其他事件方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 用C++实现简单随机二元四则运算
- 下一篇: freemarker小例子