{"id":293,"date":"2006-01-20T14:31:52","date_gmt":"2006-01-20T06:31:52","guid":{"rendered":"http:\/\/j178.mtgbb.com\/30"},"modified":"2006-01-20T14:31:52","modified_gmt":"2006-01-20T06:31:52","slug":"getelementbyclass","status":"publish","type":"post","link":"https:\/\/j178.mtgbb.com\/?p=293","title":{"rendered":"getElementByClass"},"content":{"rendered":"<p>\u8cc7\u6599\u4f86\u6e90: <a href=\"http:\/\/www.webmasterworld.com\/forum91\/1729.htm\" target=\"_blank\">webmasterworld<\/a>\u3001<a href=\"http:\/\/www.mixfog.com\/blog\/2005\/10\/getelementbyclass.htm\" target=\"_blank\">mixfog<\/a><\/p>\n<p>Javascript \u4e2d \u7684 <span style=\"color: #0000ff;\">getElementById<\/span> \u5341\u5206\u5e38\u7528\uff0c\u4f46\u5728\u6a19\u6e96\u7684\u9801\u9762\u4e2d\uff0c\u4e00\u500bid\u53ea\u80fd\u51fa\u73fe\u4e00\u6b21\uff0c\u5982\u679c\u6211\u60f3\u540c\u6642\u63a7\u5236\u591a\u500b\u5143\u7d20\uff0c\u4f8b\u5982\u9ede\u4e00\u500b\u93c8\u63a5\uff0c \u8b93\u591a\u500b\u5c64\u96b1\u85cf\uff0c\u8a72\u600e\u9ebc\u505a\uff1f<\/p>\n<p>\u7528 class\uff0c\u7576\u7136\uff0c\u540c\u4e00\u500bclass\u662f\u53ef\u4ee5\u5141\u8a31\u5728\u9801\u9762\u4e2d\u91cd\u8907\u51fa\u73fe\u7684\uff0c\u90a3\u9ebc\u6709\u6c92\u6709getElementByClass\u5462\uff1f<\/p>\n<p>\u6c92\u6709\uff0c \u4f46\u662f\u53ef\u4ee5\u89e3\u6c7a\uff1a<\/p>\n<pre lang=\"javascript\" line=\"1\">\n&lt;script language=\"javascript\"&gt;\n\n\/\/Create an array\nvar allPageTags = new Array();\n\nfunction hideDivWithClasses(theClass) {\n\n\/\/Populate the array with all the page tags\nvar allPageTags=document.getElementsByTagName(\"div\");\n\n\/\/Cycle through the tags using a for loop\nfor (i=0; i &lt;\u00a0 allPageTags.length;) {\n\n\/\/Pick out the tags with our class name\nif (allPageTags[i].className==theClass) {\n\/\/Manipulate this in whatever way you want\nallPageTags[i].style.display='none';\ni++;\n}\n}\n}\n&lt;\/script&gt;\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u8cc7\u6599\u4f86\u6e90: webmasterworld\u3001mixfog Javascript \u4e2d \u7684 getElementBy &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[26],"class_list":["post-293","post","type-post","status-publish","format-standard","hentry","category-javascript-vbscript","tag-javascript-2"],"_links":{"self":[{"href":"https:\/\/j178.mtgbb.com\/index.php?rest_route=\/wp\/v2\/posts\/293","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/j178.mtgbb.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/j178.mtgbb.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/j178.mtgbb.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/j178.mtgbb.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=293"}],"version-history":[{"count":0,"href":"https:\/\/j178.mtgbb.com\/index.php?rest_route=\/wp\/v2\/posts\/293\/revisions"}],"wp:attachment":[{"href":"https:\/\/j178.mtgbb.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=293"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/j178.mtgbb.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=293"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/j178.mtgbb.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=293"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}