{"id":4547,"date":"2013-05-26T04:35:40","date_gmt":"2013-05-25T19:35:40","guid":{"rendered":"http:\/\/www.webcyou.com\/?p=4547"},"modified":"2013-05-26T04:38:58","modified_gmt":"2013-05-25T19:38:58","slug":"javascript-%e3%82%af%e3%83%ad%e3%83%bc%e3%82%b8%e3%83%a3-%e9%85%8d%e5%88%97%e3%81%a7%e5%8f%96%e5%be%97-%e8%a6%81%e7%b4%a0%e3%81%ae%e9%a0%86%e7%95%aa%e5%8f%96%e5%be%97","status":"publish","type":"post","link":"https:\/\/www.webcyou.com\/?p=4547","title":{"rendered":"Javascript \u30af\u30ed\u30fc\u30b8\u30e3 \u914d\u5217\u3067\u53d6\u5f97 \u8981\u7d20\u306e\u9806\u756a\u53d6\u5f97"},"content":{"rendered":"<p>\u3069\u3082\u3002\u3053\u308c\u307e\u305f\u304a\u4e45\u3057\u3076\u308a\u306a\u611f\u3058\u3067\u3059\u3002<\/p>\n<p>\u304a\u4ed5\u4e8b\u304c\u30af\u30c3\u30bd\u5fd9\u3057\u304f\u5168\u304f\u4ed6\u306e\u3053\u3068\u304c\u3067\u304d\u306a\u3044\u4eca\u65e5\u3053\u306e\u9803\u3067\u3059\u3002<\/p>\n<p>\u304c\u6545\u306b\u826f\u3044\u4f5c\u54c1\u3082\u51fa\u6765\u3066\u3044\u308b\u306e\u3067\u3001\u307e\u3041\u3044\u3044\u304b\u3041\u3068\u601d\u3046\u4eca\u65e5\u3053\u306e\u9803\u3067\u3059\u3002<\/p>\n<p>\u3067\u3001\u75b2\u308c\u3082\u30d4\u30fc\u30af\u306b\u6765\u3066\u3044\u308b\u305b\u3044\u304b\u3001\u3069\u3046\u3082\u57fa\u790e\u7684\u306a\u3068\u3053\u308d\u3082\u5206\u304b\u3093\u306a\u304f\u306a\u3063\u3066\u6765\u3066\u3057\u307e\u3063\u3066\u3044\u308b\u306e\u3067\u307e\u3068\u3081\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>\u3067\u5185\u5bb9\u306f\u3068\u3044\u3046\u3068\u3001ul\u3001ol\u306a\u3069\u306e\u30ea\u30b9\u30c8\u3092\u53d6\u5f97\u3057\u305f\u3044\u6642\u306e\u51e6\u7406\u306b\u95a2\u3057\u3066\u3067\u3059\u3002<\/p>\n<p><strong>HTML<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n&lt;ul class=&quot;list&quot;&gt;\r\n  &lt;li&gt;1-1&lt;\/li&gt;\r\n  &lt;li&gt;1-2&lt;\/li&gt;\r\n&lt;\/ul&gt;\r\n&lt;ul class=&quot;list&quot;&gt;\r\n  &lt;li&gt;2-1&lt;\/li&gt;\r\n  &lt;li&gt;2-2&lt;\/li&gt;\r\n  &lt;li&gt;2-3&lt;\/li&gt;\r\n  &lt;li&gt;2-4&lt;\/li&gt;\r\n&lt;\/ul&gt;\r\n&lt;ul class=&quot;list&quot;&gt;\r\n  &lt;li&gt;3-1&lt;\/li&gt;\r\n  &lt;li&gt;3-2&lt;\/li&gt;\r\n  &lt;li&gt;3-3&lt;\/li&gt;\r\n&lt;\/ul&gt;\r\n<\/pre>\n<p>\u4f8b\u3048\u3070\u3001\u3053\u3093\u306a\u611f\u3058\u3067\u30ea\u30b9\u30c8\u304c\u3042\u3063\u305f\u3068\u3057\u307e\u3059\u3002<\/p>\n<p>\u4f55\u3082\u8003\u3048\u305a\u3001\u307e\u305a\u306ful\u3092\u53d6\u5f97\u3059\u308b\u3068\u3059\u308b\u3068\u3001<\/p>\n<p><strong>Javascript<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n'use strict';\r\n(function(global) {\r\n  var document = global.document;\r\n  function list() {\r\n    var ul = document.querySelectorAll(&quot;.list&quot;);\r\n    for(var i = 0, il = ul.length; i &lt; il; i++) {\r\n      console.log(ul&#x5B;i]);\r\n    }\r\n  }\r\ndocument.addEventListener('DOMContentLoaded', list, false);\r\n})(this);<\/pre>\n<p>\u3053\u3093\u306a\u611f\u3058\u3067\u53d6\u5f97\u51fa\u6765\u308b\u304b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p><strong>console<\/strong><\/p>\n<p><a href=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/233ca8552a343ec327e8c5186b96b18e.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/233ca8552a343ec327e8c5186b96b18e.png\" alt=\"\" title=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2013-05-26 3.28.58\" width=\"201\" height=\"66\" class=\"alignnone size-full wp-image-4548\" \/><\/a><\/p>\n<p>\u7d9a\u3044\u3066\u3001\u4f55\u3082\u8003\u3048\u305ali\u3092\u5168\u3066\u53d6\u5f97\u3057\u3088\u3046\u3068\u3059\u308b\u3068\u3001<\/p>\n<p><strong>Javascript<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n'use strict';\r\n(function(global) {\r\n  var document = global.document;\r\n  function list() {\r\n    var ul = document.querySelectorAll(&quot;.list &gt; li&quot;);        \r\n    for(var i = 0, il = ul.length; i &lt; il; i++) {\r\n      console.log(ul&#x5B;i]);\r\n    }\r\n  }\r\ndocument.addEventListener('DOMContentLoaded', list, false);\r\n})(this);\r\n<\/pre>\n<p>\u3053\u3093\u306a\u611f\u3058\u3067\u53d6\u5f97\u51fa\u6765\u308b\u304b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p><strong>console<\/strong><\/p>\n<p><a href=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/3388dd1164d1b8a1bead6cd82f327d82.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/3388dd1164d1b8a1bead6cd82f327d82.png\" alt=\"\" title=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2013-05-26 3.45.06\" width=\"106\" height=\"173\" class=\"alignnone size-full wp-image-4549\" \/><\/a><\/p>\n<p>\u66f4\u306b\u3053\u308c\u306b\u300c\u30af\u30ea\u30c3\u30af\u3055\u308c\u305f\u969b\u306e\u9806\u756a\u3092\u53d6\u5f97\u300d\u306a\u3069\u3092\u8003\u616e\u3059\u308b\u969b\u3001\u4f55\u3068\u306a\u304f\u3053\u308c\u3067\u3044\u3051\u305d\u3046\u306a\u6c17\u304c\u3057\u307e\u3059\u304c\u3001<\/p>\n<p><strong>Javascript<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">'use strict';\r\n(function(global) {\r\n  var document = global.document;\r\n  function list() {\r\n    var ul = document.querySelectorAll(&quot;.list &gt; li&quot;);\r\n    for(var i = 0, il = ul.length; i &lt; il; i++) {\r\n      ul&#x5B;i].addEventListener('click', function() {\r\n            console.log(i);\r\n      }, false);\r\n    }\r\n  }\r\ndocument.addEventListener('DOMContentLoaded', list, false);\r\n})(this);<\/pre>\n<p>\u3053\u3046\u3084\u308b\u3068\u3001\u7d50\u679c\u306f\u3069\u308c\u3092\u30af\u30ea\u30c3\u30af\u3057\u3066\u3082\u3001\u300c9\u300d\u304c\u8fd4\u3063\u3066\u304d\u3066\u3001\u610f\u56f3\u3057\u305f\u7d50\u679c\u3068\u306f\u306a\u308a\u307e\u305b\u3093\u3002<\/p>\n<p>\u7406\u7531\u3068\u3057\u3066\u306f\u3001for\u6587\u3067\u5b9a\u7fa9\u3057\u305f\u5909\u6570i\u306f\u4fdd\u6301\u3055\u308c\u305a\u3001\u6700\u7d42\u7684\u306b\u30ea\u30b9\u30c8\u306e\u6570\uff08\u3053\u3053\u3067\u306f9\uff09\u3068\u306a\u3063\u3066\u3057\u307e\u3046\u305f\u3081\u3067\u3059<\/p>\n<p>\u305d\u3053\u3067\u3001\u30af\u30ed\u30fc\u30b8\u30e3\u30fc\u3092\u7528\u3044\u3066\u53d6\u5f97\u3057\u305f\u308a\u3057\u307e\u3059\u3002<\/p>\n<p>\u30af\u30ed\u30fc\u30b8\u30e3\u30fc\u3068\u306f\u300c\u95a2\u6570\u306e\u4e2d\u306e\u95a2\u6570\u300d\u3068\u304b\u300c\u5909\u6570\u3092\u4fdd\u6301\u3059\u308b\u300d\u306a\u3069\u3067\u899a\u3048\u3089\u308c\u3066\u3044\u308b\u304b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u30af\u30ed\u30fc\u30b8\u30e3\u30fc\u3067\u30b0\u30b0\u30eb\u3068\u3067\u3067\u3066\u304f\u308b\u306e\u306f\u3001\u3053\u3093\u306a\u95a2\u6570\u304c\u591a\u3005\u30d2\u30c3\u30c8\u3059\u308b\u304b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p><strong>Javascript<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">var f = function() {\r\n    var i = 0;\r\n    return function() {\r\n        return i++;\r\n    }\r\n}();\r\nconsole.log(f());\/\/ 0\u3092\u51fa\u529b\r\nconsole.log(f());\/\/ 1\u3092\u51fa\u529b\r\nconsole.log(f());\/\/ 2\u3092\u51fa\u529b<\/pre>\n<p>&nbsp;<\/p>\n<p>\u5b9f\u884c\u3059\u308b\u5ea6\u306b\u30ab\u30a6\u30f3\u30c8\u304c\u5897\u3048\u3066\u884c\u304f\u3088\u3046\u306a\u95a2\u6570\u3067\u3059\u3002<\/p>\n<p>\u30af\u30ed\u30fc\u30b8\u30e3\u306e\u7279\u5fb4\u3068\u3057\u3066\u3001\u300c\u95a2\u6570\u304c\u7d42\u4e86\u3057\u305f\u3042\u3068\u3082\u305d\u306e\u30ed\u30fc\u30ab\u30eb\u5909\u6570\u304c\u53c2\u7167\u3067\u304d\u308b\u300d\u306a\u3069\u3092\u5229\u7528\u3057\u305f\u95a2\u6570\u3068\u306a\u3063\u3066\u304a\u308a\u307e\u3059\u3002\uff08\u30af\u30ed\u30fc\u30b8\u30e3\u30fc\u306b\u95a2\u3057\u3066\u306f\u9577\u304f\u306a\u308a\u305d\u3046\u306a\u306e\u3067\u3001\u8a73\u7d30\u306f\u4ed6\u30b5\u30a4\u30c8\u7b49\u3092\u53c2\u7167\u304f\u3060\u3055\u3044\u3002\uff09<\/p>\n<p>\u3053\u306e\u30af\u30ed\u30fc\u30b8\u30e3\u30fc\u306e\u7279\u5fb4\u3092\u5229\u7528\u3057\u4ee5\u4e0b\u306e\u69d8\u306a\u611f\u3058\u3067\u300c\u30af\u30ea\u30c3\u30af\u3057\u305f\u8981\u7d20\u306e\u9806\u756a\u300d\u3092\u53d6\u5f97\u51fa\u6765\u308b\u304b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p><strong>Javascript<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nfor(var i = 0, il = ul.length; i &lt; il; i++) {\r\n  (function(arg) {\r\n    ul&#x5B;i].addEventListener('click', function() {\r\n      console.log(arg);\r\n    }, false);\r\n  })(i);\r\n}<\/pre>\n<p>\u3067\u306f\u3001\u672c\u984c\u3078\u3068\u3002\u3002\u3002<\/p>\n<p>ul\u306e\u9806\u756a\u3068li\u306e\u9806\u756a\u3092\u305d\u308c\u305e\u308c\u53d6\u5f97\u3057\u305f\u3044\u3068\u3057\u307e\u3059\u3002<\/p>\n<p>\u3064\u307e\u308a\u3001html\u306b\u8a18\u8ff0\u3057\u3066\u3044\u308b1-1\u306e\u8981\u7d20\u306ful[0][0]\u30011-2\u306e\u8981\u7d20\u306ful[0][1]\u30012-2\u306e\u8981\u7d20\u306f[1][1]\u306e\u3088\u3046\u306b\u3068\u3002<\/p>\n<p>\u305d\u3093\u306a\u5834\u5408\u306f\u3001<\/p>\n<p><strong>Javascript<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n'use strict';\r\n(function(global) {\r\n  var document = global.document;\r\n  function list() {\r\n    var ul = document.querySelectorAll(&quot;.list&quot;),\r\n        li;\r\n    for(var i = 0, il = ul.length; i &lt; il; i++) {\r\n      li = ul&#x5B;i].querySelectorAll(&quot;li&quot;);\r\n      for(var n = 0; n &lt; li.length; n++) {\r\n        ul&#x5B;i]&#x5B;n] = li&#x5B;n];        \r\n        console.log(ul&#x5B;i]&#x5B;n]);\r\n      }\r\n    }\r\n  }\r\ndocument.addEventListener('DOMContentLoaded', list, false);\r\n})(this);\r\n<\/pre>\n<p>\u3068\u3001ul\u306e\u6570\u306e\u5206for\u6587\u3067\u53d6\u5f97\u3057\u3001\u3055\u3089\u306b\u5b50\u8981\u7d20\u3067\u3042\u308b\u30ea\u30b9\u30c8\u306e\u6570for\u6587\u3067\u56de\u3059\u3053\u3068\u306b\u3088\u3063\u3066\u53d6\u5f97\u51fa\u6765\u308b\u304b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u66f4\u306b\u3001\u3053\u308c\u3089\u306e\u30ea\u30b9\u30c8\u3092\u30af\u30ea\u30c3\u30af\u3057\u305f\u969b\u306e\u9806\u756a\u3064\u307e\u308a\u3001\u4f55\u756a\u76ee\u306eul\u306e\u4f55\u756a\u76ee\u306eli\u304b\uff1f<\/p>\n<p>\u3063\u3066\u306e\u304c\u77e5\u308a\u305f\u3044\u5834\u5408\u3001\u5148\u307b\u3069\u306e\u30af\u30ed\u30fc\u30b8\u30e3\u30fc\u3092\u7528\u3044\u308b\u3053\u3068\u306b\u3088\u3063\u3066\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002<\/p>\n<p><strong>Javascript<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n'use strict';\r\n(function(global) {\r\n  var document = global.document;\r\n  function list() {\r\n    var ul = document.querySelectorAll(&quot;.list&quot;),\r\n        li;\r\n    for(var i = 0, il = ul.length; i &lt; il; i++) {\r\n      li = ul&#x5B;i].querySelectorAll(&quot;li&quot;);\r\n      for(var n = 0; n &lt; li.length; n++) {\r\n        (function(arg) {\r\n          (function(len) {\r\n            ul&#x5B;i]&#x5B;n] = li&#x5B;n];        \r\n            ul&#x5B;i]&#x5B;n].addEventListener('click', function() {\r\n              console.log(arg + ':' + len);\r\n            }, false);\r\n          })(n);\r\n        })(i);\r\n      }\r\n    }\r\n  }\r\ndocument.addEventListener('DOMContentLoaded', list, false);\r\n})(this);\r\n<\/pre>\n<p>\u30af\u30ea\u30c3\u30af\u3059\u308b\u3068\u3001\u914d\u5217\u3067\u683c\u7d0d\u3057\u305f\u9806\u756a\u3092\u53d6\u5f97\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p><strong>console<\/strong><\/p>\n<p><a href=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/4aec6a61ccdc505857031cab0100c5ff.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/4aec6a61ccdc505857031cab0100c5ff.png\" alt=\"\" title=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2013-05-26 4.25.48\" width=\"57\" height=\"105\" class=\"alignnone size-full wp-image-4550\" \/><\/a><\/p>\n<p>\u3044\u3084\u3041\u3001\u3061\u3087\u3063\u3074\u308a\u8003\u3048\u3066\u3057\u307e\u3044\u307e\u3057\u305f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3069\u3082\u3002\u3053\u308c\u307e\u305f\u304a\u4e45\u3057\u3076\u308a\u306a\u611f\u3058\u3067\u3059\u3002 \u304a\u4ed5\u4e8b\u304c\u30af\u30c3\u30bd\u5fd9\u3057\u304f\u5168\u304f\u4ed6\u306e\u3053\u3068\u304c\u3067\u304d\u306a\u3044\u4eca\u65e5\u3053\u306e\u9803\u3067\u3059\u3002 \u304c\u6545\u306b\u826f\u3044\u4f5c\u54c1\u3082\u51fa\u6765\u3066\u3044\u308b\u306e\u3067\u3001\u307e\u3041\u3044\u3044\u304b\u3041\u3068\u601d\u3046\u4eca\u65e5\u3053\u306e\u9803\u3067\u3059\u3002 \u3067\u3001\u75b2\u308c\u3082\u30d4\u30fc\u30af\u306b\u6765\u3066\u3044\u308b\u305b\u3044\u304b\u3001\u3069\u3046\u3082\u57fa\u790e\u7684\u306a\u3068\u3053\u308d [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[176,166,37,47,179,50,46],"class_list":["post-4547","post","type-post","status-publish","format-standard","hentry","category-javascript","tag-html5","tag-iphone","tag-iphone-","tag-javascript-2","tag-jquery","tag-jquery-mobile","tag-js"],"_links":{"self":[{"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/posts\/4547","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4547"}],"version-history":[{"count":3,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/posts\/4547\/revisions"}],"predecessor-version":[{"id":4552,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/posts\/4547\/revisions\/4552"}],"wp:attachment":[{"href":"https:\/\/www.webcyou.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4547"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4547"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4547"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}