querySelector,querySelectorAll

//返回第一个元素相匹配的CSS选择器{expr}.
// Returns first element that matches CSS selector {expr}.
// 查询可以被限制在{container}的后代
// Querying can optionally be restricted to {container}’s descendants
function $(expr, container) {
  return typeof expr === "string"? (container || document).querySelector(expr) : expr || null;
}

// 返回所有匹配的元素的CSS选择器作为数组.
// Returns all elements that match CSS selector {expr} as an array.
// 查询可以被限制在{container}的后代
// Querying can optionally be restricted to {container}’s descendants
function $$(expr, container) {
  return [].slice.call((container || document).querySelectorAll(expr));
}

Tips:You can change the code before run.

THE END
分享
二维码
打赏
< <上一篇
下一篇>>