我有一些 JSON,其中包含数千种不同的 CSS 选择器,这里是各种示例......
"#mid_ad_title",
"#mid_mpu",
"#mid_roll_ad_holder",
".SidebarAdvert",
".SitesGoogleAdsModule",
".SkyAdContainer",
"a[href$=\"/vghd.shtml\"]",
"a[href*=\"/adrotate/adrotate-out.php?\"]",
"a[href^=\"http://ad-apac.doubleclick.net/\"]",
"#mn #center_col > div > h2.spon:first-child + ol:last-child",
"#resultspanel > #topads",
"#rhs_block > #mbEnd"
如您所见,JSON 由各种选择器组成——有些只是一个类,有些只是一个 ID,有些是混合的。
我想根据选择器的类型使用相关的 JavaScript“get”方法,所以对于只是 ID 的选择器,我会使用document.getElementById()
等。
有谁知道任何正则表达式或在我循环遍历 JSON 时会告诉我选择器类型的东西?即"class", "id", "other"
。
提前致谢。