Home >Web Front-end >JS Tutorial >Dom and browser compatibility instructions_DOM

Dom and browser compatibility instructions_DOM

WBOY
WBOYOriginal
2016-05-16 18:17:441398browse

As a web front-end worker, are you often confused by browser compatibility issues at work? For example, CSS style? It is obvious that the normal web page is displayed in IE browser. When it comes to FireFox or Google Chrome, it's a mess. Maybe you have encountered similar problems when using JavaScript and Dom to write web page scripts. Obviously, the script runs normally in the FireFox browser. An error occurred in IE. For example, get the source target that triggers the js event. There are also issues with mouse position or element position. Dynamically bind events to elements, etc. . . I will list below the incompatibility issues of some Dom commands in browsers such as IE and FireFox!
Limited by space. I will not give a detailed explanation of the Dom instructions mentioned on this page. Please click on the relevant command name to learn detailed explanations and examples.
When using JavaScript to obtain the source target of the triggered event, IE and FireFox behave differently, that is to say which element in the web page triggered the event

  1. Use srcElement in IE browser
  2. Use target in FireFox browser

Problems using Dom to obtain and change text within web page tag elements

  1. Use innerText in IE browser
  2. Use textContent in FireFox browser

Mouse position within the element

  1. Use offsetX and offsetY in IE to obtain the position of the mouse on a certain element in the web page
  2. FireFox uses layerX and layerY to get the position of the mouse on a certain element in the web page

Problems with dynamically binding and deleting events for web pages or elements

  1. The method of binding events in IE is attachEvent
  2. The method to delete bound events in IE is detachEvent
  3. The method to bind events in FireFox is addEventListener
  4. The method to delete bound events in FireFox is removeEventListener

To be continued... Director Kang on: 2010-07-24

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn