javascript - JavaScript 是否有现有的 CSS3 选择器解析器?

标签 javascript css-selectors

任何人都知道将解析 CSS3 选择器的代码片段,如下所示:

"form#network_template[method='put'][action='#form_{keyname}']"

对此:

{
  tag: "form",
  id: "network_template",
  method: "put",
  action: "#form_{keyname}"
}

或者这个:

<form id="network_template" method="put" action="#form_{keyname}">

最佳答案

假设您想在标题中请求 CSS3 选择器解析器Slick ,在 Mootools 中使用,可以完成这项工作;来自 github 页面:

Slick.parse("h1, h2, ul > li, .things")

{
"raw": "h1, h2, ul > li, .things",
"expressions": [
    [{ "combinator":" ", "tag": "h1" }],
    [{ "combinator":" ", "tag": "h2" }],
    [{ "combinator":" ", "tag": "ul" }, { "combinator": ">", "tag": "li" }],
    [{ "combinator":" ", "tag": "*", "classList": ["things"], "classes": [{"value": "things", "regexp":RegExp }] }]
]
}

Mootools 还可以直接从选择器创建具有适当属性的元素。

关于javascript - JavaScript 是否有现有的 CSS3 选择器解析器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4002305/

相关文章:

css - 添加内容第 nth-child 到分页

javascript - querySelectorAll 语法无效

javascript - 如何从 Markdown 链接到 VSCode 代码文件中的特定符号?

javascript - 获取 UL 内父 LI 的大小?

javascript - 将对象从 SQL 查询函数传递到单独的函数

css - 哪个是 CSS 中更好的实践 - 多个位置的单个通用选择器或多个特定选择器?

javascript - JQuery 不适用于 ajax 返回的内容

javascript - 我如何使用 Gulp 使用 gulp-mocha 显示测试覆盖率

python - ElementNotInteractableException : element not interactable error while trying to search for stock on www. finanzen.net 使用 Selenium 和 Python

css - 是否有 CSS 父级选择器?