{"id":297,"date":"2025-05-12T17:41:18","date_gmt":"2025-05-12T08:41:18","guid":{"rendered":"https:\/\/yowamon3.com\/?p=297"},"modified":"2025-05-12T17:41:18","modified_gmt":"2025-05-12T08:41:18","slug":"%e3%82%bb%e3%83%ac%e3%82%af%e3%83%88%e3%83%9c%e3%83%83%e3%82%af%e3%82%b9%e3%81%ae%e6%93%8d%e4%bd%9c","status":"publish","type":"post","link":"https:\/\/yowamon3.com\/?p=297","title":{"rendered":"\u30bb\u30ec\u30af\u30c8\u30dc\u30c3\u30af\u30b9\u306e\u64cd\u4f5c"},"content":{"rendered":"\n<h2 class=\"wp-block-heading jinr-heading d--bold\">\u524d\u63d0<\/h2>\n\n\n\n<p>\u30bb\u30ec\u30af\u30c8\u30dc\u30c3\u30af\u30b9\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b\u3082\u306e\u3068\u3059\u308b\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>&lt;select id=&quot;my-select&quot;&gt;\n&lt;\/select&gt;<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading jinr-heading d--bold\">\u9805\u76ee\u306e\u8ffd\u52a0<\/h2>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>const select = document.getElementById(&#39;my-select&#39;);\n\nconst newOption = document.createElement(&#39;option&#39;);\nnewOption.value = &#39;1&#39;\nnewOption.text = &#39;One&#39;\n\nselect.appendChild(newOption)<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading jinr-heading d--bold\">\u9805\u76ee\u306e\u524a\u9664<\/h2>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>const select = document.getElementById(&#39;my-select&#39;);\n\nwhile(select.children.length &gt; 0) {\n    select.removeChild(select.lastChild);\n}<\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading jinr-heading d--bold\">\u5148\u982d\u306e\u8981\u7d20\u3060\u3051\u6b8b\u3057\u3066\u305d\u306e\u4ed6\u306e\u9805\u76ee\u3092\u524a\u9664<\/h3>\n\n\n\n<p>\u5148\u982d\u306b\u300c\u9078\u629e\u3057\u3066\u304f\u3060\u3055\u3044\u300d\u306e\u3088\u3046\u306a\u56fa\u5b9a\u306e\u8981\u7d20\u304c\u3042\u308b\u5834\u5408\u306f\u3053\u306e\u65b9\u6cd5\u3092\u4f7f\u3046\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>const select = document.getElementById(&#39;my-select&#39;);\n\nwhile(select.children.length &gt; 1) {\n    select.removeChild(select.lastChild);\n}<\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading jinr-heading d--bold\">\u7279\u5b9a\u306e\u6761\u4ef6\u3092\u6e80\u305f\u3059\u8981\u7d20\u3060\u3051\u3092\u524a\u9664<\/h3>\n\n\n\n<p>\u76f4\u611f\u7684\u306b\u306f\u5148\u982d\u304b\u3089\u8abf\u3079\u305f\u3044\u3068\u3053\u308d\u3060\u304c\u3001\u5f8c\u308d\u304b\u3089\u691c\u8a3c\u3057\u3066\u524a\u9664\u3059\u308b\u3002<br>\u5148\u982d\u304b\u3089\u8abf\u3079\u305f\u5834\u5408\u3001\u524a\u9664\u3057\u305f\u5206\u8981\u7d20\u756a\u53f7\u304c\u305a\u308c\u308b\u305f\u3081\u3001\u30b9\u30ad\u30c3\u30d7\u3055\u308c\u308b\u8981\u7d20\u304c\u51fa\u3066\u304d\u3066\u3057\u307e\u3046\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>const select = document.getElementById(&#39;my-select&#39;);\n\nfor(let i = select.options.length - 1; i &gt; 0; i--) {\n    const option = select.options[i];\n    if(option.value.includes(&#39;\u524a\u9664&#39;)) {\n        select.remove(i);\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading jinr-heading d--bold\">\u9805\u76ee\u306e\u9078\u629e<\/h2>\n\n\n\n<h3 class=\"wp-block-heading jinr-heading d--bold\">\u5148\u982d\u306e\u8981\u7d20\u3092\u9078\u629e<\/h3>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>const select = document.getElementById(&#39;my-select&#39;);\n\nselect.selectedIndex = 0;<\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading jinr-heading d--bold\">\u7279\u5b9a\u306e\u5024\u3092\u6301\u3063\u305f\u8981\u7d20\u3092\u9078\u629e\u3057\u305f\u3044\u5834\u5408<\/h3>\n\n\n\n<p>select.value\u306b\u4ee3\u5165\u3059\u308b\u5024\u306f\u9078\u629e\u3057\u305f\u3044\u9805\u76ee\u306evalue\u3092\u8a2d\u5b9a\u3059\u308b\u3002\u4ee5\u4e0b\u306e\u4f8b\u306e\u5834\u5408\u3001value\u304c\u7a7a\u6587\u5b57\u306e\u9805\u76ee\u304c\u9078\u629e\u3055\u308c\u308b\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>const select = doucment.getElementById(&#39;my-select&#39;);\nselect.value = &#39;&#39;;<\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading jinr-heading d--bold\">\u8907\u6570\u9078\u629e\u53ef\u80fd\u3068\u3057\u3066\u3044\u308b\u5834\u5408\u306b\u5148\u982d\u9805\u76ee\u306e\u307f\u9078\u629e\u3055\u305b\u305f\u3044<\/h3>\n\n\n\n<p>\u8907\u6570\u9078\u629e\u53ef\u80fd\u306a\u5834\u5408\u3001\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3067\u5148\u982d\u8981\u7d20\u306e\u307f\u3092\u9078\u629e\u3057\u305f\u72b6\u614b\u306b\u3067\u304d\u308b\u3002\u3059\u3079\u3066\u306e\u9078\u629e\u3092\u89e3\u9664\u3057\u305f\u3044\u5834\u5408\u306f\u5358\u7d14\u306bfalse\u3092\u4ee3\u5165\u3059\u308c\u3070\u3088\u3044\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>const select = document.getElementById(&#39;my-select&#39;);\n\nArray.from(select.options).forEach((opt, index) =&gt; {\n  opt.selected = (index === 0);\n});<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading jinr-heading d--bold\">\u9078\u629e\u3055\u308c\u305f\u5024\u306e\u53d6\u5f97<\/h2>\n\n\n\n<h3 class=\"wp-block-heading jinr-heading d--bold\">\u9078\u629e\u3067\u304d\u308b\u306e\u304c1\u9805\u76ee\u306e\u5834\u5408<\/h3>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>const select = document.getElementById(&#39;my-select&#39;);\n\n\/\/ \u9078\u629e\u3057\u305f\u9805\u76ee\u306evalue\u3060\u3051\u53d6\u5f97\u3067\u304d\u308c\u3070\u826f\u3044\u5834\u5408\nconst selectedValue = select.value;\n\n\/\/ \u9078\u629e\u3057\u305f\u9805\u76ee\u306e\u30c6\u30ad\u30b9\u30c8\u3082\u53d6\u5f97\u3057\u305f\u3044\u5834\u5408\nconst selectedOption = select.options[select.selectedIndex];<\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading jinr-heading d--bold\">\u8907\u6570\u9078\u629e\u53ef\u80fd\u306a\u5834\u5408<\/h3>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>const select = document.getElementById(&#39;my-select&#39;);\n\nconst selectedValues = Array.from(select.selectedOptions).map(opt =&gt; opt.value);<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading jinr-heading d--bold\">onChange\u30a4\u30d9\u30f3\u30c8<\/h2>\n\n\n\n<h3 class=\"wp-block-heading jinr-heading d--bold\">\u7121\u540d\u95a2\u6570\u3092\u5b9a\u7fa9\u3059\u308b\u5834\u5408<\/h3>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>document.getElementById(&#39;my-select).addEventListener(&#39;change&#39;, (e) =&gt; {\n  \/\/ \u51e6\u7406\u3092\u66f8\u304f\n});\n<\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading jinr-heading d--bold\">HTML\u3067\u5b9a\u7fa9\u3059\u308b\u5834\u5408<\/h3>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>&lt;select id=&quot;my-select&quot; onChange=&quot;handleMySelectOnChange()&quot;&gt;\n&lt;\/select&gt;<\/code><\/pre><\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u63d0 \u30bb\u30ec\u30af\u30c8\u30dc\u30c3\u30af\u30b9\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b\u3082\u306e\u3068\u3059\u308b\u3002 \u9805\u76ee\u306e\u8ffd\u52a0 \u9805\u76ee\u306e\u524a\u9664 \u5148\u982d\u306e\u8981\u7d20\u3060\u3051\u6b8b\u3057\u3066\u305d\u306e\u4ed6\u306e\u9805\u76ee\u3092\u524a\u9664 \u5148\u982d\u306b\u300c\u9078\u629e\u3057\u3066\u304f\u3060\u3055\u3044\u300d\u306e\u3088\u3046\u306a\u56fa\u5b9a\u306e\u8981\u7d20\u304c\u3042\u308b\u5834\u5408\u306f\u3053\u306e\u65b9\u6cd5\u3092\u4f7f\u3046\u3002 \u7279\u5b9a\u306e\u6761\u4ef6\u3092\u6e80\u305f\u3059 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jinr_url_youtube":"","_jinr_pip_youtube":false,"_jinr_time_youtube":"","_jinr_thumb_youtube":"","_jinr_media_youtube":"","_jinr_category_edit":false,"_jinr_category":"","_jinr_title_display":false,"_jinr_snsbutton_display":false,"_jinr_ads_display":false,"_jinr_thumbnail_display":false,"_jinr_profile_display":false,"_jinr_representations_display":false,"_jinr_relatedpost_display":false,"_jinr_sidebar1col_display":false,"_jinr_sidebar2col_display":false,"_jinr_seotitle_display":"","_jinr_description_display":"","_jinr_keyword_display":"","_jinr_hastag_display":"","_jinr_canonical_display":"","_jinr_noindex_display":false,"_jinr_paidpost":false,"_jinr_paidpost_product_id":"","_jinr_headtag_article":"","footnotes":""},"categories":[110],"tags":[113,111,112],"class_list":["post-297","post","type-post","status-publish","format-standard","hentry","category-javascript","tag-dom","tag-javascript","tag-112"],"views":"36","_links":{"self":[{"href":"https:\/\/yowamon3.com\/index.php?rest_route=\/wp\/v2\/posts\/297","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yowamon3.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yowamon3.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yowamon3.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yowamon3.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=297"}],"version-history":[{"count":1,"href":"https:\/\/yowamon3.com\/index.php?rest_route=\/wp\/v2\/posts\/297\/revisions"}],"predecessor-version":[{"id":298,"href":"https:\/\/yowamon3.com\/index.php?rest_route=\/wp\/v2\/posts\/297\/revisions\/298"}],"wp:attachment":[{"href":"https:\/\/yowamon3.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=297"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yowamon3.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=297"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yowamon3.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=297"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}