javascript falsy value
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title></title> 5 <script type="text/javascript"> 6 window.onload = function () { 7 for (var f = document.createElement("table"), a = [null, "", " ", 0, "0", void 0, NaN, !1], e, c, b = 0; b <= a.length; b++)if (e = document.createElement("tr"), f.appendChild(e), 0 == b) { 8 e.className = " title"; 9 for (var d = 0; d <= a.length; d++)0 == b && 0 == d ? (c = document.createElement("td"), c.innerHTML = "Compare") : (c = document.createElement("td"), c.innerHTML = "string" === typeof a[d - 1] ? '"' + a[d - 1] + '"' : a[d - 1] + ""), e.appendChild(c) 10 } else for (d = 0; d <= a.length; d++)0 == d ? (c = document.createElement("td"), c.innerHTML = "string" === typeof a[b - 11 1] ? '"' + a[b - 1] + '"' : a[b - 1] + "", e.appendChild(c), c.className = " title") : (c = document.createElement("td"), c.innerHTML = a[b - 1] == a[d - 1], e.appendChild(c)); 12 a = f.childNodes; 13 for (b = 0; b < a.length; b++)a[b].className || (a[b].className = 0 == b % 2 ? "odd" : "even"), a[b].oldClassName = a[b].className, a[b].onmouseover = function () { 14 this.className += " highlight" 15 }, a[b].onmouseout = function () { 16 this.className = this.oldClassName 17 }, document.getElementsByTagName("div")[0].appendChild(f) 18 }; 19 20 </script> 21 <style> 22 /* html{ 23 text-align: center; 24 }*/ 25 table { 26 width: 60%; 27 font-family: Arial, sans-serif; 28 text-align: left; 29 margin: 0 auto; /* 这里主要作用是设置左右margin为auto,这样就能在让容器居中,否则在FF中只是文字在容器中居中.容器继承了body的text-align:center ,文字也居中了 */ 30 /*border-color: #000000;*/ 31 border: #334455 solid thin; 32 } 33 34 body { 35 text-align: center; 36 background: #666677; 37 } 38 39 .odd { 40 background-color: #cccccc; 41 } 42 43 .even { 44 background-color: #c6eccb; 45 } 46 47 .title { 48 background-color: #ffc353; 49 } 50 51 .highlight { 52 background-color: #eecc88; 53 font-style: italic; 54 font-family: fantasy; 55 } 56 57 td { 58 font-family: Helvetica, serif; 59 font-size: 12px; 60 width: 50px; 61 } 62 63 tr { 64 line-height: 1em; 65 } 66 67 tr.title>td { 68 text-align: center; 69 font-size: 14px; 70 font-weight: bold; 71 font-style: italic; 72 line-height: 1.5em; 73 } 74 75 p { 76 font: italic normal bold 14px normal; 77 } 78 79 h1 { 80 font: italic normal bold 20pt "Times New Roman"; 81 } 82 </style> 83 84 </head> 85 <body> 86 <div> 87 <h1>hello world</h1> 88 89 <p>注意:在if()判断体内自动转为false的是:0,'',undefined,null,NaN。而' ','0'在if()判断体中为true</p> 90 </div> 91 </body> 92 </html>