任何人都知道将解析 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/