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
IE
How the browser renders (resolves
IE10
Under
JS
or 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