https://github.com/rwson/js-selector
基于原生js封装的一些快捷选择器
https://github.com/rwson/js-selector
Last synced: 3 months ago
JSON representation
基于原生js封装的一些快捷选择器
- Host: GitHub
- URL: https://github.com/rwson/js-selector
- Owner: rwson
- License: mit
- Created: 2015-05-30T15:04:36.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2015-05-31T02:37:30.000Z (about 11 years ago)
- Last Synced: 2025-03-11T03:41:53.365Z (over 1 year ago)
- Language: JavaScript
- Size: 137 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# js-selector
基于原生js封装的一些简单选择器
----------
####大致可以分下面几种情况讨论
- 简单的id/class/tagName选择器,并且参数中不含特殊字符(" ",">"),
就是平常的document.getElement....
- 匿名方法function(){},就丢给window.onload = function(){}处理
- 含有" "的,就是下代选择器,先把当前元素取出来,再取出它的子集元素
- 含有">"的,就是亲子代选择器,同样先把当前元素取出来,再取出它的子
集元素,同时要保证它的子集元素的父节点就是当前节点才能通过
----------
####API
我们可以使用下面几种选择器
$s("#test-id")
$s(".test-class")
$s("p")
$s(".test-children #children2 .children2-1")
$s(".test-children #children2 p")
$s(".test-first-child>.first-child2")
$s(".test-first-child>div p")
会返回一个对象,取出具体元素集合需用$("p").elements来取。