JavaScript Common accumulation

Source: Internet
Author: User

One, JS animation inconsistent with the action to solve:
123 if (!$ (" #handle"). Is (": Animated")) {//Determine if the element is in an animated state }
Second, stop event bubbling
1234567891011 Event.stoppropagation ();-Suppress JS error Window.onerror = function () {return true; } try {/*try to do*/} catch (E) {/*do this if try error */}
Third, view JS object properties
1234567 var res = '; var obj = eval (obj); For ( var p in eval (obj)) {var prop = p + ': ' + obj[p] + ' \ n '; res + = prop;} Alert (res);
Iv. Disable the Submit button when the page refreshes
123 Window.onbeforeunload = function () {$ (': Submit '). attr (' disabled '), true);}

Note : Opera browsers do not support, other browsers avoid using the same pseudo-protocol on the same page "javascrpt:"

V. Getting events
123456789 var getEvent = function () {var ieevent = window.event; var ffevent = arguments.callee.caller.arguments[0]; //arguments.callee Current Execution function //arguments.callee.caller The caller of the current execution function //arguments.callee.caller.arguments[0] The first parameter of the current function caller var e = ieevent | | ffevent; return e;}
Six, get keyboard code
1234567 var Getkcode = function () {var ieevent = window.event; var ffevent = arguments.callee.caller.arguments[0]; var e = ieevent | | ffevent; var kcode = E.keycode | | E.which; return kcode;}
Seven, mouse slide in/slide out style switch
123 $ ("div"). On ("MouseOver mouseout", function () {$ (this). Toggleclass (" Over ");});
Eight, click the mouse, Show/Hide Toggle
1234567 $ ("#panel h5.head"). Toggle (function () {$ (this). Toggleclass ("highlight"); $ (this). Next (). Toggle (), andfunction () {$ (this). Toggleclass ("highlight"); $ (this). Next (). Toggle ();});
Nine, JS debugging
12345 Console.log (); //Print variables Console.dir (); //Print objects Console.dirxml (); //Print node Console.trace (); //Print function call track window.document.title = str;
Ten. Binding events for child element collections
123 $ ("div"). Delegate ("button","click",function () {$ ("p "). Slidetoggle ();});
Xi. Custom IEHow the browser renders (resolves IE10Under JSor plug-in failure):

If the kernel is installed, the Chrome kernel is used Chrome to render the page [chrome=1] , and if it is not installed, the highest version of IE kernel is used for rendering[IE=edge]:

1 <Meta http-equiv= "x-ua-compatible" content="ie=edge,chrome=1"/>
12. Registration Events
12345 //Standard browser form1.addeventlistener (' submit ', function (e) {e.preventdefault (); //Block browser default action e.stoppropagation (); //block Event stream Generation });
12345 //IE8 and earlier versions of IE browser form1.attachevent (' submit ', function () { Event.cancelbubble = true; //Block browser Default actions--IE8 and earlier versions of IE browser Event.returnvalue = false; //block Event Stream Generation--IE8 and earlier versions ie browser }

Common JavaScript accumulation

Related Article

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.