Common JS compatibility issues

Source: Internet
Author: User

1. Get the distance of the scroll bar

var Stop=document.documentelement.scrolltop | | Document.body.scrollTop

2. Get non-inline styles

IE:CURRENTSTYLE[ATTR]

Standard: Getcomputedstyle[attr]

function GetStyle (obj,attr) {

if (Obj.currentstyle) {

return obj.currentstyle[attr];

}else{

Return getComputedStyle (Obj,false) [attr];

}

}

3. Get the Event object

var e = e | | Event

4. Get keyboard information

E.keycode | | E.which

5. Blocking the browser's default behavior

function Prevent (e) {

if (E.preventdefault) {

E.preventdefault ();

}else{

E.returnvalue=false;

}

}

6. Block Event bubbling

E.stoppropagation? E.stoppropagation (): e.cancelbubble=true;

7. Event Monitoring

AddEventListener ()

Attachevent ()

8. Event Unbind

RemoveEventListener ()

DetachEvent ()

9. Get the event source

E.target | | E.srcelement;

Common JS compatibility issues

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.