{"id":2809,"date":"2018-12-12T16:52:28","date_gmt":"2018-12-12T07:52:28","guid":{"rendered":"http:\/\/anada.cloudfree.jp\/?p=2809"},"modified":"2018-12-12T16:57:51","modified_gmt":"2018-12-12T07:57:51","slug":"jquery3%e8%a6%9a%e6%9b%b8%e3%80%80%e5%b1%9e%e6%80%a7%e3%83%bb%e9%9a%8e%e5%b1%a4%e3%81%a8%e4%bb%98%e3%81%8d%e5%90%88%e3%81%86","status":"publish","type":"post","link":"http:\/\/anada.cloudfree.jp\/?p=2809","title":{"rendered":"JQuery3\u899a\u66f8\u3000\u5c5e\u6027\u30fb\u968e\u5c64\u3068\u4ed8\u304d\u5408\u3046"},"content":{"rendered":"<p>HTML\u3092\u521d\u3081\u3066\u89e6\u3063\u305f\u306e\u306f22\u3068\u304b23\u306e\u9803\u3067\u3001\u3082\u304620\u5e74\u4ee5\u4e0a\u524d\u306e\u8a71\u306b\u306a\u3063\u3066\u3057\u307e\u3063\u305f\u3002<br \/>\n\u305d\u306e\u3053\u308d\u306f\u30bf\u30b0\u306f\u5927\u6587\u5b57\u3067\u66f8\u304f\u306e\u304c\u666e\u901a\u3060\u3063\u305f\u3002<\/p>\n<p>\u3044\u3064\u306e\u9593\u306b\u304bID\u3084NAME\u3001CLASS\u3067\u30b9\u30bf\u30a4\u30eb\u3092\u6307\u5b9a\u3067\u304d\u308b\u4e16\u306e\u4e2d\u306b\u306a\u3063\u3066\u3057\u307e\u3063\u305f\u3002<br \/>\n\u30bf\u30b0\u306f\u5c0f\u6587\u5b57\u3067\u66f8\u304f\u306e\u304c\u5f53\u7136\u306b\u306a\u3063\u305f\u3002<\/p>\n<p>\u305d\u3057\u3066\u4eca\u3001\u5c5e\u6027\u3092\u81ea\u5206\u3067\u52dd\u624b\u306b\u4f5c\u3063\u3066\u30c7\u30fc\u30bf\u64cd\u4f5c\u3059\u308b\u6642\u4ee3\u3002<br \/>\njs\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3082\u3044\u3063\u3071\u3044\u4e16\u306e\u4e2d\u306b\u51fa\u56de\u3063\u3066\u3044\u308b\u304c\u3001\u4f55\u3092\u3084\u3063\u3066\u3044\u308b\u306e\u304b\u308f\u304b\u3089\u306a\u3044\u3084\u3089\u3001\u4f59\u8a08\u306a\u3053\u3068\u3092\u3059\u308b\u308f\u3067\u3001\u7d50\u5c40\u81ea\u5206\u3067\u30b4\u30ea\u30b4\u30ea\u4f5c\u3063\u305f\u65b9\u304c\u30ab\u30b9\u30bf\u30de\u30a4\u30ba\u3057\u3084\u3059\u3044\u3093\u3067\u306f\u306a\u3044\u306e\u304b\uff1f\u306a\u3069\u3068\u5f8c\u623b\u308a\u3067\u304d\u306a\u3044\u65c5\u8def\u306e\u4e00\u6b69\u3092\u3092\u8e0f\u307f\u51fa\u3057\u3066\u3057\u307e\u3046\u3002<\/p>\n<h4 style=\"color:#003399;\">\u25a0 \u5c5e\u6027<\/h4>\n<p>\u4f8b\u3048\u3070\u306e\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30c6\u30fc\u30d6\u30eb\u69cb\u6210\u306e\u5834\u5408\u3067\u3044\u3046\u306a\u3089\u3070\u3001\u300cdata-no\u300d\u3068\u3044\u3046\u306e\u304c\u52dd\u624b\u306b\u4f5c\u3063\u305f\u5c5e\u6027\u3002<br \/>\n\u3053\u306e\u5c5e\u6027\u306e\u8a2d\u5b9a\u5024\u3092\u53d6\u5f97\u3059\u308b\u65b9\u6cd5\u3092\u30e1\u30e2\u3059\u308b\u3002<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;table id=&quot;tab1&quot;&gt;\r\n    &lt;thead&gt;\r\n        &lt;tr&gt;\r\n            &lt;th data-no='1'&gt;COL1&lt;\/th&gt;\r\n            &lt;th data-no='2'&gt;COL2&lt;\/th&gt;\r\n            &lt;th data-no='3'&gt;COL3&lt;\/th&gt;\r\n        &lt;\/tr&gt;\r\n    &lt;\/thead&gt;\r\n    &lt;tbody&gt;\r\n        &lt;tr&gt;\r\n            &lt;td data-cd=&quot;101&quot;&gt;DATA1-1&lt;\/td&gt;\r\n            &lt;td data-cd=&quot;102&quot;&gt;DATA1-2&lt;\/td&gt;\r\n            &lt;td data-cd=&quot;103&quot;&gt;DATA1-3&lt;\/td&gt;\r\n        &lt;\/tr&gt;\r\n        &lt;tr&gt;\r\n            &lt;td data-cd=&quot;201&quot;&gt;DATA2-1&lt;\/td&gt;\r\n            &lt;td data-cd=&quot;202&quot;&gt;DATA2-2&lt;\/td&gt;\r\n            &lt;td data-cd=&quot;203&quot;&gt;DATA2-3&lt;\/td&gt;\r\n        &lt;\/tr&gt;\r\n    &lt;\/tbody&gt;\r\n&lt;\/table&gt;\r\n<\/pre>\n<p>JQuery\u3067\u3001th\u30bf\u30b0\u3092\u30af\u30ea\u30c3\u30af\u3057\u305f\u3068\u304d\u306b\u3001\u305d\u306edata-no\u304c\u4f55\u304b\u3092\u30a2\u30e9\u30fc\u30c8\u8868\u793a\u3055\u305b\u3066\u307f\u308b\u3002<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    $(document).on('click', '#tab1&gt;thead&gt;tr&gt;th', function (event) {\r\n        alert($(this).attr('data-no'));\r\n    });\r\n<\/pre>\n<p>\u3053\u308c\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u66f8\u3044\u3066\u3082\u554f\u984c\u306f\u306a\u3044\u306e\u3060\u304c\u3001\u3082\u3057\u5f53\u8a72\u30c6\u30fc\u30d6\u30eb\u3001\u3042\u308b\u3044\u306f\u30c6\u30fc\u30d6\u30eb\u306e\u8981\u7d20\u304c\u52d5\u7684\u3067\u3042\u3063\u305f\u5834\u5408\u306f\u3001CLICK\u30a4\u30d9\u30f3\u30c8\u304c\u691c\u77e5\u3067\u304d\u306a\u3044\u306e\u3067\u3001\u4e0a\u8a18\u306e\u3088\u3046\u306b\u66f8\u3044\u305f\u65b9\u304c\u6c4e\u7528\u7684\u306e\u3088\u3046\u3002<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    $('#tab1&gt;thead&gt;tr&gt;th').on('click', function (event) {\r\n        \/\/ \uff08\u8a18\u8f09\u7565\uff09\r\n    });\r\n<\/pre>\n<p>\u5bfe\u8c61\u306e\u6307\u5b9a\u306f\u4e0b\u306e\u3088\u3046\u306b\u7701\u7565\u3057\u3066\u66f8\u3044\u3066\u3082\u3001tbody\u30bf\u30b0\u306bth\u304c\u306a\u3044\u3068\u304d\u306f\u554f\u984c\u306a\u3044\u3002<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    $('#tab1 th').on('click', function (event) {\r\n        \/\/ \uff08\u8a18\u8f09\u7565\uff09\r\n    });\r\n<\/pre>\n<p>\u306a\u304a\u3001attr\u306f\u3001attr({\u8981\u7d20\u540d})\u3068\u3059\u308b\u3068\u3001\u6307\u5b9a\u3057\u305f\u8981\u7d20\u306e\u5024\u304c\u3042\u308c\u3070\u305d\u306e\u8a2d\u5b9a\u3092\u8fd4\u3057\u3001\u306a\u3044\u3068\u304d\u306fundefinded\u3092\u8fd4\u3059\u3002<br \/>\n\u305d\u3057\u3066\u3001\u6307\u5b9a\u3057\u305f\u8981\u7d20\u306b\u5024\u3092\u8a2d\u5b9a\u3059\u308b\u3068\u304d\u306f\u3001<strong> attr({\u8981\u7d20\u540d}, {\u8a2d\u5b9a\u5024}) <\/strong>\u3068\u3059\u308b\u3002<\/p>\n<hr>\n<h4 style=\"color:#003399;\">\u25a0 \u968e\u5c64\uff08\u89aa\u30fb\u5b50\uff09<\/h4>\n<p>\u6b21\u306b\u968e\u5c64\uff08\u89aa\u30fb\u5b50\uff09\u3092\u8003\u616e\u3057\u306a\u304c\u3089\u5024\u3092\u53d6\u308b\u65b9\u6cd5\u3092\u30e1\u30e2\u3057\u3066\u304a\u304f\u3002<br \/>\n\u306f\u3058\u3081\u306b\u30a4\u30d9\u30f3\u30c8\u306e\u5bfe\u8c61\u8981\u7d20\u3092\u300c$(&#8216;#tab1>thead>tr>th&#8217;)\u300d\u3068\u3001\u6069\u7740\u305b\u304c\u307e\u3057\u304f\u8a18\u8ff0\u3057\u305f\u306e\u3060\u304c\u3001\u3053\u308c\u306f\u89aa\u5b50\u95a2\u4fc2\u3092\u308f\u304b\u308a\u3084\u3059\u304f\u3059\u308b\u305f\u3081\u3067\u3082\u3042\u308b\u3002<\/p>\n<p>#tab\u306e\u5b50\u4f9b\u304cthead\u3001\u305d\u306e\u5b50\u4f9b\u306ftr\u3001\u305d\u306e\u5b50\u4f9b\u306fth<\/p>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u9006\u306b\u8a00\u3046\u3068\u3001th\u306e\u89aa\u306ftr\u3001tr\u306e\u89aa\u306f\u30fb\u30fb\u30fb\u3068\u3001\u3082\u3046\u66f8\u304b\u306a\u3044\u3051\u3069\u305d\u3093\u306a\u611f\u3058\u3002<\/p>\n<h5 style=\"color:#003399;\">\uff1e \u968e\u5c64\uff08\u89aa\uff09<\/h5>\n<p>\u89aa\u306f\u7c21\u5358\u306b\u53d6\u308c\u308b\u3002\u306a\u3093\u305b\uff11\u3064\u3060\u304b\u3089\u3002<\/p>\n<p>\u89aa\u3067\u3042\u308b(tr)\u306eHTML\u8a18\u8ff0\u5185\u5bb9\u3092\u30a2\u30e9\u30fc\u30c8\u8868\u793a\u3055\u305b\u3066\u307f\u308b\u3002<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    $(document).on('click', '#tab1&gt;thead&gt;tr&gt;th', function (event) {\r\n        alert($(this).parent().html());\r\n    });\r\n<\/pre>\n<p>\u7c21\u5358\u3002\u89aa\u306e\u89aa(thead)\u306fparent().parent()\u3002<br \/>\n\u89aa\u306e\u89aa\u306e\u89aa(#tab1)\u306a\u3089\u3001parent().parent().parent()\u3068\u3044\u3046\u3053\u3068\u306b\u3002\u3082\u306f\u3084for\u6587\u3067\u3082\u4f7f\u3063\u305f\u65b9\u304c\u3088\u3055\u305d\u3046\u3060\u3002<\/p>\n<h5 style=\"color:#003399;\">\uff1e \u968e\u5c64\uff08\u5b50\uff09<\/h5>\n<p>\u5b50\u306e\u53d6\u308a\u65b9\u306f\u3044\u308d\u3044\u308d\u3002<\/p>\n<p>\u8a66\u3057\u306b#tab1 tbody tr \u306e\u884c\u3092\u30af\u30ea\u30c3\u30af\u3057\u305f\u3089\u3001\u5b50\u8981\u7d20(td)\u3092\u9806\u756a\u306b\u3068\u3063\u3066\u3001\u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u51fa\u529b\u3057\u3066\u307f\u308b\u3002<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    $(document).on('click', '#tab1&gt;tbody&gt;tr', function (event) {\r\n        $(this).children().each(function (event) {    \/\/ (a)\r\n            console.log($(this).html());              \/\/ (b)\r\n        });\r\n    });\r\n<\/pre>\n<p>(a)\u306e$(this)\u306f\u300ctr\u300d\u306e\u8981\u7d20\u306e\u3053\u3068\u3002<br \/>\n(b)\u306e$(this)\u306f\u5b50\u8981\u7d20\u300ctd\u300d\u306e\u3053\u3068\u3002<br \/>\n\u3053\u308c\u3060\u3068\u3001tr\u306e\u5b50\u8981\u7d20\u306f\u3059\u3079\u3066\u53d6\u5f97\u3067\u304d\u308b\u306e\u3067\u3001td\u3068th\u306e\u4e21\u65b9\u306e\u30bf\u30b0\u304c\u3042\u308b\u5834\u5408\u306f\u4e21\u65b9\u3068\u3082\u53d6\u5f97\u3067\u304d\u308b\u3002<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    $(document).on('click', '#tab1&gt;tbody&gt;tr', function (event) {\r\n        $(this).children('td').each(function (event) {\r\n            console.log($(this).html());\r\n        });\r\n    });\r\n<\/pre>\n<p>\u3053\u308c\u3060\u3068\u3001tr\u306e\u5b50\u8981\u7d20\u306e\u3046\u3061td\u30bf\u30b0\u306e\u307f\u3092\u53d6\u5f97\u3067\u304d\u308b\u3002<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    $(document).on('click', '#tab1&gt;tbody&gt;tr', function (event) {\r\n        $(this).find('td').each(function (event) {\r\n            console.log($(this).html());\r\n        });\r\n    });\r\n<\/pre>\n<p>find\u3060\u3068\u3001\u5f15\u6570\u3067\u6307\u5b9a\u3057\u305f\u8981\u7d20\u3067\u3042\u308c\u3070\u3001\u5b50\u8981\u7d20\u3067\u3082\u3001\u5b6b\u8981\u7d20\u3067\u3082\u7bc4\u56f2\u5185\u3059\u3079\u3066\u304b\u3089\u53d6\u5f97\u53ef\u80fd\u306b\u306a\u308b\u3002<br \/>\n\u30b5\u30f3\u30d7\u30eb\u3060\u3068\u30c6\u30fc\u30d6\u30eb\u306e\u4e2d\u306b\u30c6\u30fc\u30d6\u30eb\u3092\u5165\u308c\u5b50\u3057\u3066\u3044\u306a\u3044\u306e\u3067\u3001\u5b50\u8981\u7d20\u306e\u307f\u53d6\u5f97\u3067\u304d\u308b\u3002<\/p>\n<p>children()\u3092\u4f7f\u3046\u304b\u3001find()\u3092\u4f7f\u3046\u304b\u306f\u5b50\u8981\u7d20\u3060\u3051\u306a\u306e\u304b\u3001\u95a2\u4fc2\u306a\u304f\u4e0b\u306e\u968e\u5c64\u3059\u3079\u3066\u306b\u9069\u7528\u3059\u308b\u306e\u304b\u3067\u6c7a\u3081\u308b\u3002<\/p>\n<h5 style=\"color:#003399;\">\uff1e \u968e\u5c64\uff08\u5b50\u8981\u7d20\u306e\uff4e\u500b\u76ee\uff09<\/h5>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    $(document).on('click', '#tab1&gt;tbody&gt;tr', function (event) {\r\n        $(this).children('td:nth-child(2)').each(function (event) {\r\n            console.log($(this).html());\r\n        });\r\n    });\r\n<\/pre>\n<p>children\u3067\u5bfe\u8c61\u3092\u6307\u5b9a\u3059\u308b\u3068\u304d\u306b\u300c:nth-child({n})\u300d\u3092\u4f7f\u3046\u3068\u3001n\u756a\u76ee\u306e\u8981\u7d20\u3060\u3051\u53d6\u5f97\u3067\u304d\u308b\u3002<\/p>\n<p>\u4eca\u65e5\u306f\u3053\u3053\u307e\u3067\u3002\u6b21\u306f\u30bd\u30fc\u30c8\u306b\u3064\u3044\u3066\u30e1\u30e2\u305b\u306d\u3070\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>HTML\u3092\u521d\u3081\u3066\u89e6\u3063\u305f\u306e\u306f22\u3068\u304b23\u306e\u9803\u3067\u3001\u3082\u304620\u5e74\u4ee5\u4e0a\u524d\u306e\u8a71\u306b\u306a\u3063\u3066\u3057\u307e\u3063\u305f\u3002 \u305d\u306e\u3053\u308d\u306f\u30bf\u30b0\u306f\u5927\u6587\u5b57\u3067\u66f8\u304f\u306e\u304c\u666e\u901a\u3060\u3063\u305f\u3002 \u3044\u3064\u306e\u9593\u306b\u304bID\u3084NAME\u3001CLASS\u3067\u30b9\u30bf\u30a4\u30eb\u3092\u6307\u5b9a\u3067\u304d\u308b\u4e16\u306e\u4e2d\u306b\u306a\u3063\u3066\u3057\u307e\u3063\u305f\u3002 \u30bf [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-2809","post","type-post","status-publish","format-standard","hentry","category-csshtmljavascript"],"_links":{"self":[{"href":"http:\/\/anada.cloudfree.jp\/index.php?rest_route=\/wp\/v2\/posts\/2809","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/anada.cloudfree.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/anada.cloudfree.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/anada.cloudfree.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/anada.cloudfree.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2809"}],"version-history":[{"count":8,"href":"http:\/\/anada.cloudfree.jp\/index.php?rest_route=\/wp\/v2\/posts\/2809\/revisions"}],"predecessor-version":[{"id":2818,"href":"http:\/\/anada.cloudfree.jp\/index.php?rest_route=\/wp\/v2\/posts\/2809\/revisions\/2818"}],"wp:attachment":[{"href":"http:\/\/anada.cloudfree.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2809"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/anada.cloudfree.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2809"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/anada.cloudfree.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2809"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}