JavaScript moves the mouse to get the rowindex position of the cell's table (compatible ie,firefox][original]_javascript tips

Source: Internet
Author: User

Code seen from Cnblogs, the author's code is not compatible with Firefox but, to help you learn why the following code is compatible with Firefox, we can compare, to help learn, for more articles can refer to the cloud-Habitat community previously published articles.

<textarea id="runcode33317"><ptml> <pead> <script language= "JavaScript" > Function mouseover () {var objtd=window.event.srcel ement; var objtr=objtd.parentelement; var Y=objtr.rowindex; var X=objtd.cellindex; Alert (x+ "" +y); </script> </pead> <body> <table width= "$" border= "1" > <tr> <td onclick= "Mouseov ER () ">&nbsp;</td> <td onclick=" mouseover () ">&nbsp;</td> <td onclick=" mouseover () " >&nbsp;</td> </tr> <tr> <td onclick= "mouseover ()" >&nbsp;</td> <TD Onclick= "MouseOver ()" >&nbsp;</td> <td onclick= "mouseover ()" >&nbsp;</td> </tr> <tr> <td onclick= "mouseover ()" >&nbsp;</td> <td onclick= "mouseover ()" >&nbsp;</td > <td onclick= "mouseover ()" >&nbsp;</td> </tr> </table> </body> </ptml> </c 0></textarea>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

The following code is a modified Firefox-compatible code for the cloud-dwelling community
<ptml> <pead> <script language= "JavaScript" > function mouseover (e) {e=window.event?window.event:e; var objtd=e.srcelement?e.srcelement:e.target; var Objtr=objtd.parentnode; var Y=objtr.rowindex; var X=objtd.cellindex; Alert (x+ "" +y); </script> </pead> <body> <table width= "$" border= "1" > <tr> <td onclick= "Mouseov ER (arguments[0]) ">&nbsp;</td> <td onclick=" mouseover (arguments[0)) ">&nbsp;</td> < TD onclick= "MouseOver (Arguments[0])" >&nbsp;</td> </tr> <tr> <td onclick= "MouseOver" ( Arguments[0] ">&nbsp;</td> <td onclick=" mouseover (arguments[0)) ">&nbsp;</td> &LT;TD onclick= "MouseOver (Arguments[0])" >&nbsp;</td> </tr> <tr> <td onclick= "MouseOver" ( Arguments[0] ">&nbsp;</td> <td onclick=" mouseover (arguments[0)) ">&nbsp;</td> &LT;TD onclick= "MouseOver (Arguments[0])" >&nbsp;</td> </tr> </table> </body> </ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

The main differences are as follows:
1. Event e.srcelement and E.target

It is often asked how to use the Event.srcelement under Firefox, in this detailed description:
Under IE, the event object has a srcelement attribute, but no target attribute; Firefox, the event object has the target attribute, but there is no srcelement attribute. But their role is quite, namely:
Firefox under the Event.target = IE under the Event.srcelement

Workaround: Use obj (obj = event.srcelement event.srcElement:event.target) to replace the event.srcelement under IE or the Event.target under Firefox.

the difference between 2.parentNode and parentelement
Use parentelement in FF invalid, search just know parentelement it is ie dedicated, ie years of hegemony caused many applications can not be compatible with other browsers, standardization is really important, hehe, must be to the standards of the Web OH

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.