{"id":2691,"date":"2016-01-29T10:56:37","date_gmt":"2016-01-29T02:56:37","guid":{"rendered":"http:\/\/blog.hoyo.idv.tw\/?p=2691"},"modified":"2016-07-20T18:02:29","modified_gmt":"2016-07-20T10:02:29","slug":"javascript-%e5%85%a8%e4%b8%9f%e5%9c%a8%e9%80%99%e8%a3%a1","status":"publish","type":"post","link":"https:\/\/blog.hoyo.idv.tw\/?p=2691","title":{"rendered":"JavaScript"},"content":{"rendered":"<h2>\u8a2d\u5b9a\u4e8c\u7dad\u9663\u5217<\/h2>\n<pre class=\"lang:js decode:true \">\/\/ \u5206\u985e\r\nvar $Category = [];\r\n$Category[1] = [];\r\n$Category[1].push({'id': '3', 'Name': 'bbbb'});\r\n$Category[1].push({'id': '6', 'Name': '3333'});\r\n$Category[2] = [];\r\n$Category[7] = [];<\/pre>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0cJavascript \u662f\u6ce8\u91cd\u8b8a\u6578\u578b\u614b\u7684\u8a9e\u8a00\uff0c\u6240\u4ee5\u6bcf\u4e00\u7dad\u9663\u5217\u90fd\u5fc5\u9808<span style=\"color: #ff0000;\">\u5148\u5ba3\u544a<\/span>\u3002<\/p>\n<p>\u6240\u4ee5 array.push() \u932f\u8aa4\u55ae\u7d14\u53ea\u662f\u6c92\u6709\u5ba3\u544a\u578b\u614b\u7684\u95dc\u4fc2<\/p>\n<p>--<\/p>\n<h2>\u87a2\u5e55\u3001\u8996\u7a97\u7684\u5bec\u9ad8<\/h2>\n<pre class=\"nums:true lang:js decode:true \">&lt;script&gt;\r\n    console.log('document.documentElement.clientWidth: '+document.documentElement.clientWidth);\r\n    console.log('document.documentElement.clientHeight: '+document.documentElement.clientHeight);\r\n    console.log('window.screen.width: '+window.screen.width);\r\n    console.log('window.screen.height: '+window.screen.height);\r\n    console.log('window.screen.availWidth: '+window.screen.availWidth);\r\n    console.log('window.screen.availHeight: '+window.screen.availHeight);\r\n    console.log('window.innerWidth: '+window.innerWidth);\r\n    console.log('window.innerHeight: '+window.innerHeight);\r\n    console.log('window.outerWidth: '+window.outerWidth);\r\n    console.log('window.outerHeight: '+window.outerHeight);\r\n&lt;\/script&gt;<\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"lang:default decode:true\">\/\/ \u87a2\u5e55\u7684\u89e3\u6790\u5ea6\r\nwindow.screen.width: 1280\r\nwindow.screen.height: 800\r\n\r\n\/\/ \u87a2\u5e55\u53ef\u4f7f\u7528\u5c3a\u5bf8\uff0c\u6263\u9664\u958b\u59cb\u5de5\u5177\u5217\r\nwindow.screen.availWidth: 1280\r\nwindow.screen.availHeight: 760\r\n\r\ndocument.documentElement.clientWidth: 861\r\ndocument.documentElement.clientHeight: 210\r\n\r\n\r\nwindow.innerWidth: 878\r\nwindow.innerHeight: 210\r\nwindow.outerWidth: 894\r\nwindow.outerHeight: 536<\/pre>\n<p>&nbsp;<\/p>\n<p>--<\/p>\n<h2>iframe \u6839\u64da\u5167\u5bb9\u9ad8\u5ea6\u8abf\u6574<\/h2>\n<ul>\n<li><a href=\"http:\/\/www.minwt.com\/webdesign-dev\/js\/112.html\" target=\"_blank\">[JS]iframe\u4f9d\u5167\u5bb9\u81ea\u52d5\u8abf\u6574\u6846\u67b6\u9ad8\u5ea6<\/a><\/li>\n<\/ul>\n<pre class=\"lang:default decode:true\">&lt;iframe id=\"frameid\" src=\"Content.html\" style=\"width: 99%; margin: 0;border: 0;\"&gt;&lt;\/iframe&gt;<\/pre>\n<p>Content.html<\/p>\n<pre class=\"lang:default decode:true\">&lt;head&gt;\r\n    &lt;script&gt;\r\n        function reSize(){\r\n            parent.document.getElementById(\"frameid\").height=document.body.scrollHeight;\r\n        }\r\n        window.onload=reSize;\r\n    &lt;\/script&gt;\r\n&lt;\/head&gt;<\/pre>\n<p>--<\/p>\n<h2>\u4e09\u5143\u904b\u7b97\u5143\u00a0Conditional (ternary) Operator<\/h2>\n<p><a href=\"https:\/\/developer.mozilla.org\/zh-CN\/docs\/Web\/JavaScript\/Reference\/Operators\/Conditional_Operator\" target=\"_blank\">\u6761\u4ef6\u8fd0\u7b97\u7b26<\/a><\/p>\n<pre class=\"lang:js decode:true \">var $a = 0;\r\nif ( $a == 0 ) {\r\n    alert('0');\r\n}\r\nelse {\r\n    alert('\u4e0d\u662f 0');\r\n}<\/pre>\n<p>\u53ef\u4ee5\u4f7f\u7528\u689d\u4ef6\u904b\u7b97\u5143\u7c21\u5316\u6210<\/p>\n<pre class=\"lang:js decode:true\">var $a = 0;\r\n($a==0) ? alert('0') : alert('\u4e0d\u662f 0') ;<\/pre>\n<p>\u9700\u8981\u57f7\u884c\u591a\u689d\u6307\u4ee4\u6642\u53ef\u4ee5\u4f7f\u7528\u00a0\u95ed\u5305 (Closure)<\/p>\n<p>--<\/p>\n<h2>Closures \u9589\u5305<\/h2>\n<ul>\n<li><a href=\"https:\/\/developer.mozilla.org\/zh-CN\/docs\/Web\/JavaScript\/Closures\" target=\"_blank\">\u95ed\u5305<\/a><\/li>\n<li><a href=\"http:\/\/sweeteason.pixnet.net\/blog\/post\/40371736-javascript-%e9%96%8b%e7%99%bc%e5%ad%b8%e7%bf%92%e5%bf%83%e5%be%97---%e5%87%bd%e6%95%b8%e7%9a%84%e5%a4%9a%e7%a8%ae%e5%af%ab%e6%b3%95%e8%88%87%e6%87%89\">Javascript \u958b\u767c\u5b78\u7fd2\u5fc3\u5f97 - \u51fd\u6578\u7684\u591a\u7a2e\u5beb\u6cd5\u8207\u61c9\u7528\u9650\u5236<\/a><\/li>\n<\/ul>\n<pre class=\"lang:js decode:true\">(function(){\r\n    $(\"#aaa\").val('a');\r\n    $(\"#bbb\").val('b');\r\n})()<\/pre>\n<p>--<\/p>\n<h2>\u7522\u751f\u4e00\u7d44 0.00 ~100.00 \u7684\u96a8\u6a5f\u6578\u503c<\/h2>\n<ul>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/1527803\/generating-random-numbers-in-javascript-in-a-specific-range\">Generating random numbers in Javascript in a specific range?<\/a><\/li>\n<li><a href=\"http:\/\/i-yow.blogspot.tw\/2010\/08\/javascript.html\">JavaScript \u53d6\u5c0f\u6578\u9ede<\/a><\/li>\n<\/ul>\n<pre class=\"nums:true lang:default decode:true\">&lt;div&gt;\r\n    &lt;div id=\"Data\"&gt;&lt;\/div&gt;\r\n&lt;\/div&gt;\r\n\r\n&lt;script&gt;\r\n    function getRandomArbitrary(min, max) {\r\n        return (Math.random() * (max - min) + min).toFixed(2);\r\n    }\r\n    \r\n    setInterval(function(){\r\n        $Data = getRandomArbitrary(0, 100);\r\n        $(\"#Data\").html($Data);\r\n    }, 1000);\r\n&lt;\/script&gt;\r\n<\/pre>\n<p>--<\/p>\n<h2>\u6b63\u898f\u8868\u793a\u5f0f<\/h2>\n<ul>\n<li><a href=\"https:\/\/developer.mozilla.org\/zh-TW\/docs\/Web\/JavaScript\/Guide\/Regular_Expressions\" target=\"_blank\">\u6b63\u898f\u8868\u793a\u5f0f<\/a><\/li>\n<\/ul>\n<p>\u4f7f\u7528\u5728 jQuery\u00a0Validation Engine 2.6.2 \u4e0a\u7684\u4e00\u500b\u81ea\u5b9a\u7fa9\u898f\u5247\u7bc4\u4f8b<\/p>\n<p>\u76f4\u63a5\u7de8\u8f2f\u00a0jquery.validationEngine-zh_TW.js \u6a94\u6848\uff0c\u5c07\u898f\u5247\u589e\u52a0\u5728\u5167<\/p>\n<pre class=\"nums:true lang:js decode:true\">\"RuleExec\": {\r\n    'regex': \/^[^\\'\\\"\\\\\\\\]+$\/,\r\n    'alertText': '\u4e0d\u5141\u8a31\u8f38\u5165 \\' \" \\\\ \u7279\u6b8a\u5b57\u5143 '\r\n}<\/pre>\n<p>\u589e\u52a0\u4e00\u500b\u4e0d\u5141\u8a31\u8f38\u5165 ' \" \\ \u00a0\u4e09\u500b\u7279\u6b8a\u5b57\u5143\u7684\u898f\u5247<\/p>\n<p>--<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p class=\"pvc_stats all \" data-element-id=\"2691\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> &nbsp;5,860&nbsp;total views<\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u8a2d\u5b9a\u4e8c\u7dad\u9663\u5217 \/\/ \u5206\u985e va...<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p class=\"pvc_stats all \" data-element-id=\"2691\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> &nbsp;5,860&nbsp;total views<\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[180],"tags":[232,190,212,233,213],"_links":{"self":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/2691"}],"collection":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2691"}],"version-history":[{"count":13,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/2691\/revisions"}],"predecessor-version":[{"id":3979,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/2691\/revisions\/3979"}],"wp:attachment":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2691"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2691"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2691"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}