This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 1/0 = Infinity | |
| 0/0 = NaN | |
| 1/'foo' = NaN | |
| 1/Infinity = 0 | |
| (1/Infinity)*Infinity = NaN | |
| Infinity == Infinity (true) | |
| 0/0为NaN,其他数除0为Infinite |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var myRe = /d(b+)d/g; | |
| var myArray = myRe.exec("cdbbdbsbz"); | |
| console.log(RegExp.$1);//bb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function sleep(ms) { | |
| var dt = new Date(); | |
| dt.setTime(dt.getTime() + ms); | |
| while (new Date().getTime() < dt.getTime()); | |
| } | |
| // sleep(4000); | |
| console.log('setTimeout begin'); | |
| setTimeout( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function getScrollTop(){ | |
| var position = [0, 0]; | |
| if (typeof window.pageYOffset != 'undefined') { | |
| position = [ | |
| window.pageXOffset, window.pageYOffset]; | |
| } else if (typeof document.documentElement.scrollTop != 'undefined' && document.documentElement.scrollTop > 0) { | |
| position = [ | |
| document.documentElement.scrollLeft, document.documentElement.scrollTop]; | |
| } else if (typeof document.body.scrollTop != 'undefined') { | |
| position = [ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| http://jsfiddle.net/UumUP/2913/ | |
| // Function to change the content of t2 | |
| function modifyText() { | |
| var t2 = document.getElementById("t2"); | |
| t2.firstChild.nodeValue = "three"; | |
| } | |
| // add event listener to t | |
| var el = document.getElementById("t"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*Make position:fixed work in IE6!*/ | |
| .fixed-top /* position fixed Top */{position:fixed;bottom:auto;top:0;} | |
| .fixed-bottom /* position fixed Bottom */{position:fixed;bottom:0;top:auto;} | |
| .fixed-left /* position fixed Left */{position:fixed;right:auto;left:0;} | |
| .fixed-right /* position fixed right */{position:fixed;right:0;left:auto;} | |
| * html,* html body /* IE6 Fixed Position Jitter Fix */{background-image:url(about:blank);background-attachment:fixed;} | |
| * html .fixed-top /* IE6 position fixed Top */{position:absolute;bottom:auto;top:expression(eval(document.documentElement.scrollTop));} | |
| * html .fixed-right /* IE6 position fixed right */{position:absolute;right:auto;left:expression(eval(document.documentElement.scrollLeft+document.documentElement.clientWidth-this.offsetWidth)-(parseInt(this.currentStyle.marginLeft,10)||0)-(parseInt(this.currentStyle.marginRight,10)||0));} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| The common practice of rounding, namely the round() function in PHP, is to round to the nearest decimal point, that is, 1.0, 2.0, 3.0, etc. or, 10, 20, 30, etc. For example, | |
| echo round(4.25, 0); // 4 | |
| echo round(3.1415926, 2); // 3.14 | |
| echo round(299792, -3); // 300000 | |
| When I’m trying to aggregate all the customer ratings for a specific provider in one of my web hosting reviews community, I want to round the average rating to the nearest 0.5 (half the decimal) so that a half star would be correctly displayed. | |
| This is more of a mathematical problem than a PHP one. After some thinking and testing, I came up with a slightly more sophisticated solution than but the round() function: | |
| echo round(1.7 * 2) / 2; // 1.5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function getScrollXY() { | |
| var scrOfX = 0, scrOfY = 0; | |
| if( typeof( window.pageYOffset ) == 'number' ) { | |
| //Netscape compliant | |
| scrOfY = window.pageYOffset; | |
| scrOfX = window.pageXOffset; | |
| } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) { | |
| //DOM compliant | |
| scrOfY = document.body.scrollTop; | |
| scrOfX = document.body.scrollLeft; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* It is not possible to get certain styles set in css such as display using | |
| the normal javascript. So we have to use this function taken from: | |
| http://www.quirksmode.org/dom/getstyles.html */ | |
| function getStyle(el,styleProp) | |
| { | |
| var x = document.getElementById(el); | |
| if (x.currentStyle) // IE | |
| var y = x.currentStyle[styleProp]; | |
| else if (window.getComputedStyle) // FF |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* It is not possible to get certain styles set in css such as display using | |
| the normal javascript. So we have to use this function taken from: | |
| http://www.quirksmode.org/dom/getstyles.html */ | |
| function getStyle(el,styleProp) | |
| { | |
| var x = document.getElementById(el); | |
| if (x.currentStyle) // IE | |
| var y = x.currentStyle[styleProp]; | |
| else if (window.getComputedStyle) // FF |