国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > CSS > 正文

event.currentTarget和document.activeElement用法

2024-07-11 09:05:24
字體:
來源:轉載
供稿:網友

網頁制作Webjx文章簡介:firefox 的 event.currentTarget 和 ie 的 document.activeElement 這兩個完全含義不一致的對象卻被捆綁在一起做成了瀏覽器兼容代碼。 大家在google搜索的時候 都會發現 document.activeElement || event.currentTarget 的用法。

firefox 的 event.currentTarget 和 ie 的 document.activeElement 這兩個完全含義不一致的對象卻被捆綁在一起做成了瀏覽器兼容代碼。 大家在google搜索的時候 都會發現 document.activeElement || event.currentTarget 的用法。

其實這樣的用法是錯誤的,因為這兩個屬性的意義都不一樣。

event.currentTarget 

Identifies the current target for the event, as the event traverses the DOM.

識別當前事件觸發的dom

document.activeElement

Gets the object that has the focus when the parent document has focus.

獲得當前focus的對象

例子

 <script type="text/javascript"> 
 var show = function (e) {  
  alert(e.currentTarget?"獲取到了 currentTarget":"獲取到了 document.activeElement")  
  alert((e.currentTarget || document.activeElement).tagName);  
 };  
  </script><BR>  案例1: <br/><BR>  <a href="#"><img src="" border="0" alt="" onclick="show(event)"/></a> <br/> <br/><BR>  案例2: <br/><BR>  <a href="#" onclick="show(event)"><img src="" border="0" alt=""/></a> <br/><P></P> 
<P>  這兩個案例,在ie和firefox下試驗一下。</P> 

最后測試補充:后來測試了一下 document.activeElement  的支持程度,發現四大瀏覽器safari除外, ie firefox opera都提供了這個對象的支持。但是有點需要注意的,上面的例子中 opera 會把圖片作為 可以 focus的對象。導致document.activeElement的結果不一致...

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 韶山市| 玛多县| 建昌县| 永登县| 墨竹工卡县| 屏东市| 崇明县| 德江县| 长乐市| 佛教| 安远县| 溆浦县| 大渡口区| 阿坝| 黄龙县| 景谷| 南靖县| 绩溪县| 辛集市| 清镇市| 苗栗市| 大厂| 海林市| 锦屏县| 怀宁县| 武威市| 铜鼓县| 福安市| 桃源县| 合山市| 安仁县| 林周县| 什邡市| 同心县| 张家口市| 建昌县| 于都县| 芦山县| 中宁县| 商南县| 崇左市|